Home > other >  Python socket multithreaded client problems, seek guidance!! Thank you
Python socket multithreaded client problems, seek guidance!! Thank you

Time:01-28

The code is as follows:
 
From the socket import *
The import threading
The import time

Tcp_socket=socket (AF_INET SOCK_STREAM)
Tcp_socket. Connect ((10002) '192.168.10.63')



Def send_msg (device_index) :
='get tx send_msg info {}'. The format (device_index)
Tcp_socket. Send (send_msg. Encode (' utf-8))
Time. Sleep (0.5)
Recv_msg=tcp_socket. Recv (4444). The decode (" utf8 ")
Print (' % s \ n % recv_msg)


Threads=[]
For I in range (5) :
T=threading. Thread (target=send_msg, args=(I,))
Threads. Append (t)
T.s tart ()

For t in threads:
T.j oin ()



Questions as follows:
Cycle is 5 times, but each time you run to the third, with the card, the card is a minute or so no longer perform, direct stopped;


My purpose is to want to let the client concurrent query information from the server, but to run there is a problem, check the baidu for a long time did not solve,, every brother please help me have a look, thanks!



CodePudding user response:

 
Def send_msg (device_index) :
Tcp_socket=socket (AF_INET SOCK_STREAM)
Tcp_socket. Connect ((10002) '192.168.10.63')
='get tx send_msg info {}'. The format (device_index)
Tcp_socket. Send (send_msg. Encode (' utf-8))
Time. Sleep (0.5)
Recv_msg=tcp_socket. Recv (4444). The decode (" utf8 ")
Print (' % s \ n % recv_msg)
Tcp_socket. Close ()

To create a socket connection on the thread function, don't share the same connection,
  • Related