-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
34 lines (32 loc) · 973 Bytes
/
Client.py
File metadata and controls
34 lines (32 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import socket
import threading
import time
HOST = "127.0.0.1" # The server's hostname or IP address
PORT = 15432 # The port used by the server
state = True
def reciever(s):
global state
while state:
data = s.recv(1024).decode("utf-8")
print("Server: " + data)
def test_ping_loop(s): # just to show what is possible
global state
while state:
time.sleep(1)
s.sendall(bytes("HeartBeat", "utf-8"))
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
print("starting threads")
x = threading.Thread(target=reciever, args=(s,))
x.start()
y = threading.Thread(target=test_ping_loop, args=(s,))
y.start()
print("threads run")
while state:
"""for test commands or other stuff lmao"""
a = input()
b = bytes(a, "utf-8")
s.sendall(b)
if a == "fin":
state = False
s.close()