-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAS2805_Server.py
More file actions
74 lines (59 loc) · 1.83 KB
/
AS2805_Server.py
File metadata and controls
74 lines (59 loc) · 1.83 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
from socket import *
from AS2805 import AS2805
from AS2805Errors import *
# Configure the server
serverIP = "127.0.0.1"
serverPort = 9002
maxConn = 5
bigEndian = True
#bigEndian = False
# Create a TCP socket
s = socket(AF_INET, SOCK_STREAM)
# bind it to the server port
s.bind((serverIP, serverPort))
# Configure it to accept up to N simultaneous Clients waiting...
s.listen(maxConn)
# Run forever
while 1:
#wait new Client Connection
connection, address = s.accept()
while 1:
# receive message
isoStr = connection.recv(2048)
if isoStr:
print "\nInput ASCII |%s|" % isoStr
pack = AS2805()
#parse the iso
try:
if bigEndian:
pack.setNetworkISO(isoStr)
else:
pack.setNetworkISO(isoStr, False)
v1 = pack.getBitsAndValues()
for v in v1:
print 'Bit %s of type %s with value = %s' % (v['bit'], v['type'], v['value'])
if pack.getMTI() == '0800':
print "\tThat's great !!! The client send a correct message !!!"
else:
print "The client dosen't send the correct message!"
break
except InvalidAS2805, ii:
print ii
break
except:
print 'Error Occured'
break
#send answer
pack.setMTI('0810')
pack.setBit(39, '00') # Successful
if bigEndian:
ans = pack.getNetworkISO()
else:
ans = pack.getNetworkISO(False)
print 'Sending answer %s' % ans
connection.send(ans)
else:
break
# close socket
connection.close()
print "Closing..."