-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestclient.py
executable file
·57 lines (44 loc) · 1.04 KB
/
testclient.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
51
52
53
54
55
56
57
#!/usr/bin/python
import socket
import sys
import struct
import time
#main function
if __name__ == "__main__":
if(len(sys.argv) < 2) :
print 'Usage : python client.py hostname'
sys.exit()
host = sys.argv[1]
port = 8888
#create an INET, STREAMing socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print 'Failed to create socket'
sys.exit()
print 'Socket Created'
try:
remote_ip = socket.gethostbyname( host )
s.connect((host, port))
except socket.gaierror:
print 'Hostname could not be resolved. Exiting'
sys.exit()
print 'Socket Connected to ' + host + ' on ip ' + remote_ip
#Send some data to remote server
message = "Temp: "
i = 0
try :
#Set the whole string
while True:
print 'Sending...'
s.send(message + str(i))
print 'Sent: '+ message + str(i)
i = i+1
resp = s.recv(1024)
print resp
time.sleep(1)
except socket.error:
#Send failed
print 'Send failed'
sys.exit()
s.close()