dpallot / simple-websocket-server

A python based websocket server that is simple and easy to use.
951 stars 321 forks source link

added Asyncore classes #37

Open sphaero opened 8 years ago

sphaero commented 8 years ago

Thanks for your great work! I've added asyncore classes to your module as I needed these. This makes it very easy to integrate this websocket server into existing applications that are based on asyncore (i.e. yowsup)

You can use them as follows:

import asyncore
from SimpleWebSocketServer import AsyncoreWebSocketServer, AsyncoreWebSocketServerHandler

class SimpleAsyncoreEcho(AsyncoreWebSocketServerHandler):

   def handleMessage(self):
      self.sendMessage(self.data)

   def handleConnected(self):
      print('New client connected') 

   def handleClose(self):
      pass

if __name__ == '__main__':
   server = AsyncoreWebSocketServer("", 8000, SimpleAsyncoreEcho)
   asyncore.loop()
sphaero commented 8 years ago

I'm not sure I got the message deque usage correct. Why is there? Is just a buffering mechanism to prevent sending lots of small messages?