-
Notifications
You must be signed in to change notification settings - Fork 0
/
homm3_battle_client.py
33 lines (27 loc) · 1.03 KB
/
homm3_battle_client.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
import socket
import argparse
import json
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--port', dest='port', default=9999,
help='tcp server port', type=int)
parser.add_argument('--host', dest='host', default='localhost',
help='tcp host url')
args = parser.parse_args()
# @@@@@@@@@@@@ TEST DATA @@@@@@@@@@@@#
obj = {
"test": True,
"dump": True,
"test_json": True
}
data = json.dumps(obj)
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
# Create a socket (SOCK_STREAM means a TCP socket)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
# Connect to server and send data
sock.connect((args.host, args.port))
sock.sendall(bytes(data + "\n", "utf-8"))
# Receive data from the server and shut down
received = str(sock.recv(1024), "utf-8")
print("Sent: {}".format(data))
print("Received: {}".format(received))