def __init__(self, host: str=None): ''' Parameters: host : str with ip to connect to or None if server Example: game = Game() # Creates a new game instance which will be server game2 = Game("localhost") # New instance that will connect to host on local machine ''' self._score = [0, 0] # The current score. First index is current player, second is the opponent self._myturn = None self.host = host # None if server, ip string if client self.win = gui.BoxesWindow(GRID_SIZE[0], GRID_SIZE[1]) # Init connection if self.isServer(): self._connection = network.server() else: self._connection = network.client(self.host) self.myturn = self.isServer() # Server starts # Connect data recieved signal to our function and start network thread self._connection.data_recv.connect(self.on_recv) self._connection.start() # TODO: check that connection succeeded # Connect signal when a line is clicked in the ui to game logic self.win.gridWidget.lineClicked.connect(self.line_clicked)
# -*- coding: utf-8 -*- """ Created on Wed Oct 01 22:43:57 2014 @author: Juda @email: [email protected] """ import network import record import chess log=record.record() server=network.server(log) board=chess.chess(log) log.logging("Game Begin",'SHOWALL') now_player=1 player_limit=[3,3] steps=0 while True: steps+=1 now_player=1-now_player; server.send(server.AI[now_player],'action') log.logging("Send to player %d [name: %s] a signal: ACTION"%(now_player,server.AIname[now_player])) try: message=server.recieve(server.AI[now_player]) except socket.timeout: log.logging("Recieve message form player %d [name: %s]: TIME EXCEEDED LIMIT"%(now_player,server.AIname[now_player]),'SHOWALL')
''' network server test for the CC3200 based boards. ''' import os import network mch = os.uname().machine if not 'LaunchPad' in mch and not'WiPy' in mch: raise Exception('Board not supported!') server = network.server() print(server.timeout() == 300) print(server.isrunning() == True) server.deinit() print(server.isrunning() == False) server.init(login=('test-user', 'test-password'), timeout=60) print(server.isrunning() == True) print(server.timeout() == 60) server.deinit() print(server.isrunning() == False) server.init() print(server.isrunning() == True) try: server.init(1) except: print('Exception')
from vector3 import * import constants import renderer import event_handler import network import world server = False for arg in sys.argv: if arg == '-s' or arg == '-server': server = True try: if server: net = network.server( constants.port ) else: net = network.client( "pymud.no-ip.org", constants.port ) except AttributeError, e: print "ERROR: in connection, %s" % e sys.exit(-1) pygame.init() rend = renderer.renderer( vector3( constants.width, constants.height ) ) hand = event_handler.handler() scene = world.world( rend, hand, net ) while True: event = hand.process() if event and event.type == pygame.QUIT: break
# GRID_SIZEX = 100 # will probably need to be rectangular # GRID_SIZEY = 100 # # change all of this to a game class if __name__ == '__main__': # game = Game.Game() # initilize game and pygame # middleware = n.MiddleWare(game) # find which ip address to host on myhostname = socket.gethostname() (_,xindx,yindx) = myhostname.split('-') xindx = int(xindx) yindx = int(yindx) print yindx print xindx game = tron.Game([xindx, yindx]) for line in open('/etc/hosts').readlines(): if line.find(myhostname) > -1: if first_hit: my_ip_address = line.split()[0] else: first_hit = True print my_ip_address server = n.server(my_ip_address, 20000, game ) server.open_connection() while True: server.recev_connection() FPS.tick(5)