sockets - How do I get multiple clients to connect to the same source in python? -


i made class in python has socket in it. when try run multiple instances of same class error:

error: [errno 10056] connect request made on connected socket 

i can see error saying, though classes independent of each other when run. wouldn't interfere.

here's code i'm using:

class bot():      host = "localhost"     port = 6667     s = socket.socket()      def connect(self):          self.s.connect((self.host, self.port)) 

then when create bots:

bots = []  def setup_bot():      global bots      _bot = bot()      _bot.connect()      bots.append(_bot)  if __name__ == "__main__":      in range(5):          setup_bot()          sleep(1)      print "done setting up" 

how able work?

make socket s instance variable instead of setting on class. bot instances share same class attributes , thus, same socket.

class bot():     host = "localhost"     port = 6667      def __init__(self):         self.s = socket.socket()      def connect(self):         self.s.connect((self.host, self.port)) 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -