Exemplo n.º 1
0
 def __initNetworkInterface(self):
     '''
     Initiates network interface
     '''
     host = self.__visionConfig.getConfigValue("NETWORK", "serverIP")
     port = self.__visionConfig.getConfigValueInt("NETWORK", "serverPort")
     self.__socketManager = mrSocketManager(host=host, port=port, server=True, udpOn=True, useHandshake=True, name=str(self.__moduleName))
     self.__socketManager.addOnDataRecievedListener( self.__dataRecieved )
     self.__socketManager.addOnClientAddedListener( self.__clientAdded )
     
     mrLogger.log( "Vision module trying to connect to gameserver", mrLogger.LOG_LEVEL['info'] )
     
     # wait for connection
     t1 = time()
     while (time()-t1) < self.__connectionTimeout and not self.__socketManager.isConnected():
         pass
     
     if self.__socketManager.isConnected():
         mrLogger.log( "Vision module started", mrLogger.LOG_LEVEL['info'] )
         
     else:
         msg = "Vision module could not establish connection to server at " + str(host)
         msg += " on port " + str(port)
         mrLogger.log( msg, mrLogger.LOG_LEVEL['error'] )
         return False
     
     return True
Exemplo n.º 2
0
'''
from time import sleep

from mrLib.networking.mrSocketManager import mrSocketManager

def onClientAddedListener(clientdata):
    print( "SERVER: new client " + str(clientdata[1]) + " added" )
    
def onDataRecievedListener(socket, addr, data):
    print( str(socket.getSocketAddress()) + " recieved data: " + str(data) + "\n" )

if __name__ == '__main__':
    
    # create server
    print "creating server"
    server = mrSocketManager(server=True, udpOn=True, name="server", useHandshake=True)
    
    # wait for server
    while not server.isConnected():
        pass
    
    # create client
    print "creating client"
    client1 = mrSocketManager(udpOn=True, name="client1", useHandshake=True)
    
    
    client1.addOnDataRecievedListener(onDataRecievedListener)
    server.addOnClientAddedListener(onClientAddedListener)
    server.addOnDataRecievedListener(onDataRecievedListener)
    
    sleep(1)
Exemplo n.º 3
0
    mrLogger.log( str(socket.getSocketAddress()) + " recieved data: " + str(data), mrLogger.LOG_LEVEL['info'] )


# MAIN FUNCTION
if __name__ == '__main__':
    
    print "test started ..."
    mrLogger.logClear()
    mrLogger.LOGGER_LOG_LEVEL = mrLogger.LOG_LEVEL['debug']
    mrLogger.log( "sockettest started" )
    
    # generate data package
    data = "DATA"
    
    # create server
    server = mrSocketManager( server=True )
    
    # wait for server
    while not server.isConnected():
        pass
    
    # create clients
    client1 = mrSocketManager()
    client2 = mrSocketManager()
    
    # wait for clients
    while not client1.isConnected() or not client2.isConnected():
        pass
    
    # set listener
    server.addOnClientAddedListener( onClientAddedListener )