Beispiel #1
0
 def __init__(self, hub, port, username, password, udpip = '192.168.158.191', udpport = 5005):
     """
     Initialise thread, and create a TCP socket which connects to hub:port
     with specified username and password.
     """
     threading.Thread.__init__(self)
     self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.s.connect((hub, port))
     self.s.settimeout(1.5)
     self.username = username
     self.password = password
     self.ip = udpip
     self.udpport = 5005
     # The buffer which holds all commands we receive.
     self.buff = ""
     # Mutex lock for the buffer
     self.mutex = threading.Lock()
     # UDP socket for active searches
     self.udp = UDPConnection(udpip, udpport, self)
     self.udp.daemon = True
     self.udp.start()
     # last set of search results
     self.search = ''
     self.searchResults = dict()
     self.searchMutex = threading.Lock()
Beispiel #2
0
# # Server
import time

import UDPConnection

udp_connection = UDPConnection()
print udp_connection

while True:
    data = udp_connection.poll()
    if data in [udp_connection.CONNECT, udp_connection.UNCONNECT]:
        print time.time(), data
        print udp_connection
    elif data == udp_connection.PING:
        print time.time(), data
    elif data is not None:
        udp_connection.send(data)