diff options
author | TinWoodman92 <chrhodgden@gmail.com> | 2023-05-30 20:49:17 -0500 |
---|---|---|
committer | TinWoodman92 <chrhodgden@gmail.com> | 2023-05-30 20:49:17 -0500 |
commit | b9244a0e12333f441947cb1f31ad07efe9c897af (patch) | |
tree | 7346906284c8814ff670c817dd63227cc4df2345 /source_file.py | |
parent | 5f1696719ec36979005f5792a4049b30e5a7d9b2 (diff) |
WORK-IN-PROGRESS: Converting launcher and Python source file to interact via sockets.
Diffstat (limited to 'source_file.py')
-rw-r--r-- | source_file.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/source_file.py b/source_file.py index d55741a..9d10aed 100644 --- a/source_file.py +++ b/source_file.py @@ -1,3 +1,15 @@ +import socket + +HEADER = 64 +PORT = 6011 +SERVER = 'localhost' +ADDR = (SERVER, PORT) +FORMAT = 'utf-8' +DISCONNECT_MESSAGE = b'!DISSCONNECT' + +CONN = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +CONN.connect(ADDR) + def display_msg(msg): print( '\033[93m', @@ -6,6 +18,27 @@ def display_msg(msg): end='\033[0m\n' ) -msg = "hello world - Python" +def send_msg(conn, msg): + data = bytes(msg, FORMAT) + data += b' ' * (HEADER - len(data)) + conn.send(data) + +def recv_msg(conn): + msg = conn.recv(HEADER).strip() + msg = msg.decode(FORMAT) + return msg + +def terminate_connection(conn): + conn.close() + +msg = "Initializing Client - Python" display_msg(msg) + +msg = "Initialized Client - Python" +send_msg(CONN, msg) + +msg = recv_msg(CONN) +display_msg(msg) + +terminate_connection(CONN)
\ No newline at end of file |