def join(): ip = raw_input("Enter IP address of server: ") socket = socObject(ip) socket.create_client_socket() socket.connect_socket() socket.send_data("player joined game") data = socket.recv(4096) print pickle.loads(data)
def join(): ip = raw_input("Enter IP address of server: ") soc = socObject(ip) soc.create_client_socket() soc.get_data(soc, "client") soc.send_data(soc, "client", stat_dict) time.sleep(30) soc.TCPSock.close()
def host(): soc = socObject(server_ip) soc.create_server_socket() print "waiting for player to join..." client_conn, address = soc.TCPSock.accept() # connection is a new socket print "Client connected at", address[0] soc.get_data(client_conn, "server") soc.send_data(client_conn, "server", object_dict) time.sleep(30) soc.TCPSock.close()
def host(): socket = socObject(ip) socket.create_server_socket() socket.connect_socket() socket.socket_listen() while True: print "waiting for player to join..." socket.connection, socket.address = socket.TCPSock.accept() # connection is a new socket if socket.address[0] != "": print "Client connected at", socket.address[0] socket.send_data("We can now play the game...") break
#test server from socket import * import sys import pickle from socket_struct import socObject import threading import time, random dictionary = {} socket = socObject() print socket.host print socket.addr print socket.port print socket.buffer socket.create_server_socket() socket.socket_listen() class MyThread(threading.Thread): def run(self): for i in range(0,3): print "sleeping for ",int(10*random.random()), "seconds..." time.sleep(int(10*random.random())) #dictionary = socket.get_data() #this while loop needs to be a thread...
#test client from socket import * import sys import pickle from socket_struct import socObject dictionary = {'one':1, 'two':2, 'three':3} ip = '24.250.11.8' socket = socObject(ip) print socket.host print socket.addr print socket.port print socket.buffer socket.create_client_socket() socket.connect_socket() socket.send_data(dictionary) socket.close_socket() print "sent dictionary!!!!! Now closing connection..." sys.exit()