I have the below code and it receives the data I want, how I want, then terminates. How can I set this to connect to my client that always has the same IP and remain connected or listening from that client?
Its a barcode scanner and sends the data fine i just need to be always listing for it.
Servercode.py
import socket #for sockets
import sys #for exit
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM,)
except socket.error as err_msg:
print ('Unable to instantiate socket. Error code: ' + str(err_msg[0]) + ' , Error message : ' + err_msg[1])
sys.exit();
print ('Socket Initialized')
host = socket.gethostname()
port = 12345
s.bind((host, port))
s.listen(5)
print ('listening....')
conn, addr = s.accept()
print ('Got connection from', addr)
while 1:
data = conn.recv(1024)
stringdata = data.decode('ascii')
if not data: break
print ('received data:', stringdata)
conn.close()