Feb-07-2026, 01:38 AM
Hello, I am trying to make code with the socket, My goal is keep going looping without to wait for input form the socket. here my code:
any make it pass when no data?
thanks!
import socket
v = 0
def readnet():
if conn:
r = conn.recv(1024)
if not r:
pass
else:
y = r.decode("utf-8")
print("DEF READ: ", end='')
print(y)
if not conn:
print("disconnected")
return
return (str(y))
def writenet(x):
if conn:
conn.sendall(x.encode("utf-8"))
print("DEF WRITE: ", end='')
print(x)
if not conn:
print("disconnected")
return
return
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("192.168.1.200",1234))
s.listen()
conn, addr = s.accept()
s.setblocking(0)
print(f"Connected by {addr} has been established!")
blank=readnet()
writenet("HANDSHAKED")
while conn:
v=v+1
print(v)
blank=readnet()
print("disconnected")
conn.close()
print("FINISHED")You see with 'v' value and print too, I want it keep numbers up while it's looping but the "readnet()" stuck and wait for input.any make it pass when no data?
thanks!
