Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. # implements the I32CFSP and all socket handling.
  2. #If you're going to connect, read, write, etc., via a socket,
  3. #you would do that in functions written in this module.
  4.  
  5. import collections
  6. import socket
  7.  
  8. connect_four_connection = collections.namedtuple(
  9. 'connect_four_connection',
  10. ['socket', 'socket_in', 'socket_out'])
  11.  
  12. def connect(host, port) -> connect_four_connection:
  13. ''' Connects to the specified host and post '''
  14.  
  15. my_socket = socket.socket()
  16. my_socket.connect((host, port))
  17. my_socket_out = my_socket.makefile('r')
  18. my_socket_out = my_socket.makefile('w')
  19.  
  20. return connect_four_conversation(
  21. socket = my_socket
  22. socket_in = my_socket_in,
  23. socket_out = my_socket_out)
  24.  
  25.  
  26. def login(connection: connect_four_connection, username: str) -> bool:
  27. ''' Logs in with inputted username, returns true if successful, false otherwise '''
  28.  
  29.  
  30.  
  31. def send_drop(connection: connect_four_connection, drop: int) -> bool:
  32. ''' Sends a drop to the connection on behalf of the user, returning false if successful and false othewise'''
  33.  
  34. def send_pop(my_socket: socket, output) -> None:
  35. '''
  36. Sends status of the game to the server
  37. '''
  38. def _write(connection:connect_four_connection, message:str) -> None:
  39.  
  40. my_socket_out = my_socket.makefile('w')
  41. my_socket_out.write(output + '\r\n')
  42. my_socket_out.flush()
  43.  
  44. def close_socket(mySocket: socket) -> None:
  45. '''
  46. Closes the socket
  47. '''
  48. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement