-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTCGClient.py
36 lines (32 loc) · 951 Bytes
/
TCGClient.py
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
35
36
import socket
def client(shost, sport):
# Talk to server until disconnected.
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((shost, sport))
while True:
reply = s.recv(256).decode()[:256]
if len(reply) == 0:
reply = '9'
command = int(reply[0])
data = reply[1:]
if command == 0x00:
print(data)
s.send('1'.encode())
elif command == 0x01:
valid = False
while not valid:
message = input(data)
if len(message):
valid = True
s.send(message[:32].encode())
elif command == 0x09:
break
s.close()
except:
s.close()
if __name__ == '__main__':
host = '127.0.0.1'
port = 1337
while True:
client(host, port)