Skip to content

Commit

Permalink
Neocortex is a UDP server
Browse files Browse the repository at this point in the history
  • Loading branch information
greghaynes committed Oct 15, 2011
1 parent 2bb5c29 commit 2b84cae
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import asyncore, socket
import afproto

class NeocortexHandler(asyncore.dispatcher_with_send):
pass

class Neocortex(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
self.set_reuse_addr()
self.bind((host, port))
self.listen(5)
def handle_accept(self):
pair = self.accept()
if pair is None:
pass
else:
sock, addr = pair
print 'Incoming connection from %s' % repr(addr)
handler = NeocortexHandler(sock)
self.bind((host, port))

def handle_read(self):
data, addr = self.recvfrom(2048)
print str(addr)+" >> "+data

def writable(self):
return False

def handle_write(self):
pass

if __name__=='__main__':
server = Neocortex('', 8080)
Expand Down

0 comments on commit 2b84cae

Please sign in to comment.