don't close socket bc we reuse it
parent
bc6930c8db
commit
e6103169cb
22
client.py
22
client.py
|
@ -50,12 +50,13 @@ def main():
|
||||||
parser.add_argument('-b', help='Set socket backlog size',
|
parser.add_argument('-b', help='Set socket backlog size',
|
||||||
default=socket_params['backlog'])
|
default=socket_params['backlog'])
|
||||||
|
|
||||||
# Process args
|
# Process args & contants
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
rmq_host = args.s
|
rmq_host = args.s
|
||||||
socket_port = int(args.p)
|
socket_port = int(args.p)
|
||||||
socket_size = int(args.z)
|
socket_size = int(args.z)
|
||||||
socket_backlog = int(args.b)
|
socket_backlog = int(args.b)
|
||||||
|
socket_host = my_ip()
|
||||||
|
|
||||||
# Setup RabbitMQ
|
# Setup RabbitMQ
|
||||||
credentials = pika.PlainCredentials(rmq_params['username'],
|
credentials = pika.PlainCredentials(rmq_params['username'],
|
||||||
|
@ -72,6 +73,13 @@ def main():
|
||||||
channel.queue_bind(exchange=rmq_params['exchange'],
|
channel.queue_bind(exchange=rmq_params['exchange'],
|
||||||
queue=rmq_params['order_queue'])
|
queue=rmq_params['order_queue'])
|
||||||
|
|
||||||
|
# Setup socket
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
s.bind((socket_host, socket_port))
|
||||||
|
s.listen(socket_backlog)
|
||||||
|
checkpoint("Created socket at {} on port {}"
|
||||||
|
.format(socket_host, socket_port))
|
||||||
|
|
||||||
# Continuously listen for RFID ids
|
# Continuously listen for RFID ids
|
||||||
while True:
|
while True:
|
||||||
# TODO
|
# TODO
|
||||||
|
@ -79,7 +87,6 @@ def main():
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
rfid_id = '123456'
|
rfid_id = '123456'
|
||||||
socket_host = my_ip()
|
|
||||||
order_data = {'id': rfid_id, 'ip': socket_host, 'port': socket_port,
|
order_data = {'id': rfid_id, 'ip': socket_host, 'port': socket_port,
|
||||||
'size': socket_size}
|
'size': socket_size}
|
||||||
|
|
||||||
|
@ -91,16 +98,7 @@ def main():
|
||||||
body=str(order_data))
|
body=str(order_data))
|
||||||
checkpoint("Getting status for id \'{}\'".format(rfid_id))
|
checkpoint("Getting status for id \'{}\'".format(rfid_id))
|
||||||
|
|
||||||
|
|
||||||
## Wait for response from server for drink order
|
## Wait for response from server for drink order
|
||||||
# Setup socket
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
|
|
||||||
s.bind((socket_host, socket_port))
|
|
||||||
s.listen(socket_backlog)
|
|
||||||
checkpoint("Created socket at {} on port {}"
|
|
||||||
.format(socket_host, socket_port))
|
|
||||||
|
|
||||||
# Listen for reply from server
|
# Listen for reply from server
|
||||||
server, address = s.accept()
|
server, address = s.accept()
|
||||||
svr_addr = server.getpeername()[0]
|
svr_addr = server.getpeername()[0]
|
||||||
|
@ -112,10 +110,8 @@ def main():
|
||||||
recv_data = server.recv(socket_size)
|
recv_data = server.recv(socket_size)
|
||||||
recv_data = pickle.loads(recv_data)
|
recv_data = pickle.loads(recv_data)
|
||||||
checkpoint("Received data: {}".format(recv_data))
|
checkpoint("Received data: {}".format(recv_data))
|
||||||
s.close()
|
|
||||||
|
|
||||||
# Update GUI based on response
|
# Update GUI based on response
|
||||||
process_response(recv_data)
|
process_response(recv_data)
|
||||||
break
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue