Running multiple sockets at the same time in python -


i trying listen , send data several sockets @ same time. when run program en error saying:

  file "/library/frameworks/python.framework/versions/3.5/lib/python3.5/ssl.py", line 704, in __init__ if sock.getsockopt(sol_socket, so_type) != sock_stream: 

oserror: [errno 9] bad file descriptor

the first socket starts correctly, once try start new 1 error.

class bot:     def __init__(self, host, port):         self.host = host         self.port = port      sock = socket.socket()     s = none      def connect_to_server(self):         self.s = ssl.wrap_socket(self.sock)         self.s.connect((self.host, self.port)) 

above class , i'm running several instances.

def run_bots(bots):     bot in bots:         try:             threading.thread(target=bot.connect_to_server()).start()         except:             print(bot.host)             print("error: unable start thread") bots = [] b = bot('hostname.com', 1234) b1 = bot('hostname1.com', 1234) bots.append(b) bots.append(b1) run_bots(bots) 

i don't know do. have idea of problem?

you using same socket. create 1 each bot:

class bot:     def __init__(self, host, port):         self.host = host         self.port = port         self.s = none      def connect_to_server(self):         sock = socket.socket()         self.s = ssl.wrap_socket(sock)         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? -