-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
43 lines (33 loc) · 856 Bytes
/
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
34
35
36
37
38
39
40
41
42
43
import socket
import sys
import json
import time
host = "127.0.0.1"
port = 15555
print("# Creating socket")
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print("Failed to create socket")
sys.exit()
print("# Getting remote IP address")
try:
remote_ip = socket.gethostbyname(host)
except socket.gaierror:
print("Hostname could not be resolved. Exiting")
sys.exit()
print("# Connecting to server, " + host + " (" + remote_ip + ")")
s.connect((remote_ip, port))
print("# Sending data to server")
request = {"pass": "123", "test": "testo1"}
while True:
try:
s.sendall(json.dumps(request).encode("utf8"))
except socket.error:
print("Send failed")
sys.exit()
time.sleep(1)
s.close()
# print("# Receive data from server")
# reply = s.recv(4096)
# print(reply)