Update app_client.py - small modification so that client will quit if init connection cannot be established. TODO - be able to self quit when connection drops in the middle

This commit is contained in:
George 2020-03-23 01:36:43 -07:00
parent a6c558e9a1
commit 7ac56db90d

View File

@ -33,9 +33,10 @@ def create_request(action, value):
def start_connection(host, port, request):
addr = (host, port)
print("starting connection to", addr)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock = socket.create_connection(addr)
sock.setblocking(False)
sock.connect_ex(addr)
# sock.connect_ex(addr)
events = selectors.EVENT_READ | selectors.EVENT_WRITE
message = libclient.Message(sel, sock, addr, request)
sel.register(sock, events, data=message)