-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_client.py
50 lines (43 loc) · 3.1 KB
/
test_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
44
45
46
47
48
49
50
#!/usr/bin/python3 # This is client.py file
import socket
import select
import io
import time
# create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# get local machine name
host = socket.gethostname()
host = 'www.envertecportal.com'
port = 10013
buffer_size = 4096
# connection to hostname on the port.
s.connect((host, port))
# Receive no more than 1024 bytes
msg1 = bytearray.fromhex('680030681006900105970000000002000010022300027983220247200e84001c31661b3337e431fc0000000000003316')
msg2 = bytearray.fromhex('6803d66810049001059700000000000000000000111279832202479b0093001d1df91a19388e320502440100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a116')
#msg = msg[0:662]
#msg = msg.encode()
print('Sending message 1')
s.send(msg1)
print('Receiving reply')
ss = select.select
ilist = []
ilist.append(s)
time.sleep(1)
inputready, outputready, exceptready = ss(ilist, [], [])
for sock in inputready:
try:
data = sock.recv(buffer_size)
print(str(len(data)) + ' bytes received from ' + str(sock.getpeername()))
print('As hex: ' + str(data.hex()))
except OSError as e:
print('Socket error: ' + str(e))
time.sleep(1)
#self.on_close()
else:
continue
if len(data) > 0:
print('sending message 2')
s.send(msg2)
print('Closing')
s.close()