doing the tests with sockets for lan multiplayer

This commit is contained in:
Vincent Rodley 2025-08-02 19:20:56 +12:00
parent ddeeed525d
commit 093decb9ae
3 changed files with 28 additions and 5 deletions

11
client.py Normal file
View File

@ -0,0 +1,11 @@
import socket
HOST = "127.0.0.1" # The server's hostname or IP address
PORT = 65432 # The port used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(b"Hello, world")
data = s.recv(1024)
print(f"Received {data!r}")

View File

@ -82,12 +82,8 @@ def checkWin(board, player):
if all(board[col + i][row - i] == player for i in range(winCount)):
return [(col + i, row - i) for i in range(winCount)]
# Board will be 7x6.
# O = open, R = red, Y = yellow
# because this is defined like this, you could technically save a game then load from where you left off
# This is defined as columns, not rows. So tile 0 on column 0 is the bottom left tile of the board
# you index like board[column][row]
board = [
['O', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', 'O'],

16
server.py Normal file
View File

@ -0,0 +1,16 @@
import socket
HOST = "0.0.0.0"
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)