Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding more local variables to the SimpleChat class #101

Open
themindfactory opened this issue Apr 22, 2021 · 2 comments
Open

adding more local variables to the SimpleChat class #101

themindfactory opened this issue Apr 22, 2021 · 2 comments

Comments

@themindfactory
Copy link

themindfactory commented Apr 22, 2021

for every connection I want to store other variables...

in the class SimpleChat I added

class SimpleChat(WebSocket):
    def __init__(self):
        self.myvariable = "hello"

this does not work, with more research it looked like it should be more:

class SimpleChat(WebSocket):
    def __init__(self):
        super(SimpleChat, self).__init__() #tried also super(WebSocket, self).__init__()
        self.myvariable = "hello" # possibly self['myvariable'] = "hello"

nothing seems to work, not sure where to go....

hoping a python guru comes to my assistance... :-)

@Izzy3110
Copy link

are you really in python or on an other language :D

I'm currently working on a project, where i want to use it, too and i'm facing exactly the same problem

Found the class "WebSocket" in SimpleWebSocketServer.py from the package. I'd recommend doing a "fork" of it or download a copy,

  • pip uninstall SimpleWebSocketServer
  • download copy
  • change Content of class "WebSocket" SimpleWebSocketServer.py and then python setup.py in the cloned repository, this won't install from pip

Hope it helps :)

best regards & happy coding

Sascha

@pikhovkin
Copy link

Use inherit.

For example:

from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket


class WSRequestHandler(WebSocket):
    def __init__(self, server, sock, address):
        super(WSRequestHandler, self).__init__(server, sock, address)

        ...  # something yet
        
    ...  # other methods


class SimpleWSServer(SimpleWebSocketServer):
    ...  # some attrs

    def __init__(self, host, port, websocketclass, **kwargs):
        ...  # something yet

        super(SimpleWSServer, self).__init__(host, port, websocketclass)
        
        ...  # something yet


server = SimpleWSServer(HOST, PORT, WSRequestHandler)
server.serveforever()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants