Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # implements the I32CFSP and all socket handling.
- #If you're going to connect, read, write, etc., via a socket,
- #you would do that in functions written in this module.
- import collections
- import socket
- connect_four_connection = collections.namedtuple(
- 'connect_four_connection',
- ['socket', 'socket_in', 'socket_out'])
- def connect(host, port) -> connect_four_connection:
- ''' Connects to the specified host and post '''
- my_socket = socket.socket()
- my_socket.connect((host, port))
- my_socket_out = my_socket.makefile('r')
- my_socket_out = my_socket.makefile('w')
- return connect_four_conversation(
- socket = my_socket
- socket_in = my_socket_in,
- socket_out = my_socket_out)
- def login(connection: connect_four_connection, username: str) -> bool:
- ''' Logs in with inputted username, returns true if successful, false otherwise '''
- def send_drop(connection: connect_four_connection, drop: int) -> bool:
- ''' Sends a drop to the connection on behalf of the user, returning false if successful and false othewise'''
- def send_pop(my_socket: socket, output) -> None:
- '''
- Sends status of the game to the server
- '''
- def _write(connection:connect_four_connection, message:str) -> None:
- my_socket_out = my_socket.makefile('w')
- my_socket_out.write(output + '\r\n')
- my_socket_out.flush()
- def close_socket(mySocket: socket) -> None:
- '''
- Closes the socket
- '''
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement