Skip to content

Instantly share code, notes, and snippets.

@deontologician
Created December 3, 2008 07:09
Show Gist options
  • Save deontologician/31449 to your computer and use it in GitHub Desktop.
Save deontologician/31449 to your computer and use it in GitHub Desktop.
class Fastrclient(object):
""" Creates a connection object and manages all communication
with the server."""
def __init__(self, addr="localhost", port=4168):
self.clientsock = s.socket(s.AF_INET,s.SOCK_DGRAM)
self.addr = (addr,port)
self.count = 0
self.count_l = threading.Lock()
self.username = None
self.name_accepted_by_server = None
self.username_l = threading.Lock()
self.deregistered = False
self.deregistered_l = threading.Lock()
self.server_version = None
self.server_version_l = threading.Lock()
self.subscriptions = {}
self.subscriptions_l = threading.Lock()
self.recvloop = Receiver(self)
self.recvloop.setDaemon(True)
self.recvloop.start()
def __send(self,message):
"""Just a convenience function to reduce verbosity"""
return self.clientsock.sendto(message,self.addr)
class Receiver(threading.Thread):
def __init__(self, client):
threading.Thread.__init__(self)
self.client = client
def run(self):
while True:
Message = self.client.clientsock.recv(100)
Type = Message[:5]
Rest = Message[5:]
if Type == "SLIST":
self.slister(Rest)
elif Type == "SREGR":
self.finish_register(Rest)
elif Type == "SSMSG":
self.new_message(Rest)
elif Type == "SDRGR":
self.end_deregister(Rest)
else:
print "Error:",Rest
Traceback (most recent call last):
File "C:\Python26\lib\threading.py", line 522, in __bootstrap_inner
self.run()
File "C:\Documents and Settings\Phil\Desktop\Cean\fastrclient.py", line 113, in run
Message = self.client.clientsock.recv(100)
error: [Errno 10022] An invalid argument was supplied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment