Last active
February 15, 2020 21:23
-
-
Save ceffiong/e53ea472db84dc19f07a788f69d43124 to your computer and use it in GitHub Desktop.
Client application - connect to server method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: several lines of codes omitted. | |
# For previous codes see: https://gist.github.com/effiongcharles/de4b7622591b5f414ab814733fe6ff02.js | |
client = None | |
HOST_ADDR = "0.0.0.0" | |
HOST_PORT = 8080 | |
def connect_to_server(name): | |
global client, HOST_PORT, HOST_ADDR | |
try: | |
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
client.connect((HOST_ADDR, HOST_PORT)) | |
client.send(name) # Send name to server after connecting | |
entName.config(state=tk.DISABLED) | |
btnConnect.config(state=tk.DISABLED) | |
tkMessage.config(state=tk.NORMAL) | |
# start a thread to keep receiving message from server | |
# do not block the main thread :) | |
threading._start_new_thread(receive_message_from_server, (client, "m")) | |
except Exception as e: | |
tk.messagebox.showerror(title="ERROR!!!", message="Cannot connect to host: " + HOST_ADDR + " on port: " + str(HOST_PORT) + " Server may be Unavailable. Try again later") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment