-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestclient_receiver.py
executable file
·61 lines (47 loc) · 1.06 KB
/
testclient_receiver.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
58
59
60
61
#!/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
#Receive Data
try :
#Register for temp
s.send("Reg: Temp")
print 'Sent Reg: Temp'
except socket.error:
#Send failed
print 'Send failed'
sys.exit()
try :
#Set the whole string
while True:
resp = s.recv(1024)
print resp
time.sleep(1)
print 'Looping...'
except socket.error:
#Send failed
print 'Send failed'
sys.exit()
s.close()