aboutsummaryrefslogtreecommitdiff
path: root/source_file.py
diff options
context:
space:
mode:
Diffstat (limited to 'source_file.py')
-rw-r--r--source_file.py35
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