How can I make a socket connect as a background process in a function . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I make a socket connect as a background process in a function .

I tried def connect (address): Socket_name.connect (address) But it disconnects once the function is done completely .

13th Apr 2019, 10:18 AM
<<$SpiderPirate
gt;> (Offline)
2 Answers
+ 1
Hi. I am not very clear on sockets in python but I am pretty sure it is due to the scope that your codes exits when returning from the "def connect(address):" function. Try handing over the socket you want to connect too (but that would look weird) or define the socket globally
18th Apr 2019, 7:00 PM
ChrA
ChrA - avatar
0
Actually you have a point. I will try multithreading along with it.
18th Apr 2019, 7:05 PM
<<$SpiderPirate
gt;> (Offline)