-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
37 lines (25 loc) · 855 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import socket
import threading
import sprites
from termcolor import colored
COLUMNS, ROWS = 7, 6 # X, Y
HOST = socket.gethostbyname(socket.gethostname())
PORT = 4000
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
board = sprites.Board((COLUMNS, ROWS))
server.bind((HOST, PORT))
if __name__ == '__main__':
def listen():
server.listen()
while True:
conn, addr = server.accept()
try:
print(colored(f"new connection at {addr}", "red"))
except socket.error:
print(colored(f"connection closed at {addr}", "red"))
conn.close()
x = board.add_chip_to_column(1, "red")
board.add_chip_to_column(1, "red")
board.add_chip_to_column(1, "red")
board.add_chip_to_column(1, "red")
print(board.check_x_consecutive_chips(x))