import socket
import thread
s = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
s.connect(("server", 6661))
def recv():
while 1:
print(s.recv(1024))
def send():
while 1:
msg = raw_input("> ")
s.send(msg)
thread.start_new_thread(recv())
thread.start_new_thread(send())
Why does the code not run after thread recv() - I can't see where it should hang
Adjust as follow:
thread.start_new_thread(recv, ())
thread.start_new_thread(send, ())
By appending ()
right after the function name, you call recv
and send
in main thread, not in new thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With