I am writing a multi-threaded distributed network algorithm.
I have one thread that listens for new connections. Each time a new connection is established, a separate stream is launched to listen to messages from this connection.
My problem is that the socket I open works fine in both directions inside the connection listener. After I pass the socket object for this connection to the message listener, I can read data from the socket, but sending data through it does not reach the remote host.
Here is the main snip from my code:
def connection_listener(port, start_e, terminate_e): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.settimeout(1) s.bind(('', port)) s.listen(1) while (not start_e.isSet()): try: conn, addr = s.accept() msg_in = conn.recv(1024).split(":") if (msg_in[1]=="hello"):
What I would like to do is send messages like confirmation from the message listener thread using conn. Is this possible somehow or am I thinking and doing it wrong?
source share