dpallot / simple-websocket-server

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

SimpleWebSocketServer now implement serveonce() #54

Closed kalissar30 closed 7 years ago

kalissar30 commented 7 years ago

And serveforever is simply a while True over serveonce

It makes it simpler to customize a socket.

regnerus commented 7 years ago

Seems like a nice way of running the socket server, example code could be:

class ExampleConnection(WebSocket):

    def handleMessage(self):
        # echo message back to client
        self.sendMessage(self.data)

    def handleConnected(self):
        print(self.address, 'connected')

    def handleClose(self):
        print(self.address, 'closed')

server = SimpleWebSocketServer('', 8000, ExampleConnection)

while True:
    try:
        server.serveonce()
    except KeyboardInterrupt:
        server.close()
        break
masamitsu-murase commented 7 years ago

👍

dpallot commented 7 years ago

Yeah looks ok to me.