dpallot / simple-websocket-server

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

bad file descriptor when using __init__() #8

Closed pacmac closed 10 years ago

pacmac commented 10 years ago

I need to use an init function to initialize some variables and call a threaded function inside the simpleEcho class:

class SimpleEcho(WebSocket):

    def myfunc():
        do something...

    def __init__(self):
        self.varx = 1
        self.myfunc()

    def handleMessage(self):
       if self.data is None:
          self.data = ''........

But whenever I add the init the server fails with an "bad file descriptor error"

Traceback (most recent call last):
  File "websock.py", line 75, in <module>
    server.serveforever()
  File "SimpleWebSocketServer.py", line 534, in serveforever
    rList, wList, xList = select(self.listeners, [], self.listeners, 1) 
select.error: (9, 'Bad file descriptor')
pacmac commented 10 years ago

Hi, is there a solution for this ?

Many Thanks

dpallot commented 10 years ago

Hi, You need to modify your init() constructor to take the same parameters as WebSocket then you have to make sure you call its init() function.

class SimpleEcho(WebSocket):

    def myfunc(self):
        do something...

    def __init__(self, server, sock, address):
        self.myfunc()
        WebSocket.__init__(self, server, sock, address)