File: echoClient.py

package info (click to toggle)
python-iso8583 1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 240 kB
  • ctags: 230
  • sloc: python: 900; makefile: 34
file content (119 lines) | stat: -rw-r--r-- 2,921 bytes parent folder | download | duplicates (2)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""

(C) Copyright 2009 Igor V. Custodio

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""


from ISO8583.ISO8583 import ISO8583
from ISO8583.ISOErrors import *
import socket
import sys
import time


# Configure the client
serverIP = "192.168.0.100" 
serverPort = 8583
numberEcho = 5
timeBetweenEcho = 5 # in seconds

bigEndian = True
#bigEndian = False

s = None
for res in socket.getaddrinfo(serverIP, serverPort, socket.AF_UNSPEC, socket.SOCK_STREAM):
    af, socktype, proto, canonname, sa = res
    try:
		s = socket.socket(af, socktype, proto)
    except socket.error, msg:
	s = None
	continue
    try:
		s.connect(sa)
    except socket.error, msg:
	s.close()
	s = None
	continue
    break
if s is None:
    print 'Could not connect :('
    sys.exit(1)
	
	
	
for req in range(0,numberEcho):
	iso = ISO8583()
	iso.setMTI('0800')
	iso.setBit(3,'300000')	
	iso.setBit(24,'045')	
	iso.setBit(41,'11111111')	
	iso.setBit(42,'222222222222222')	
	iso.setBit(63,'This is a Test Message')
	if bigEndian:
		try:
			message = iso.getNetworkISO() 
			s.send(message)
			print 'Sending ... %s' % message
			ans = s.recv(2048)
			print "\nInput ASCII |%s|" % ans
			isoAns = ISO8583()
			isoAns.setNetworkISO(ans)
			v1 = isoAns.getBitsAndValues()
			for v in v1:
				print 'Bit %s of type %s with value = %s' % (v['bit'],v['type'],v['value'])
				
			if isoAns.getMTI() == '0810':
				print "\tThat's great !!! The server understand my message !!!"
			else:
				print "The server dosen't understand my message!"
					
		except InvalidIso8583, ii:
			print ii
			break	
		

		time.sleep(timeBetweenEcho)
		
	else:
		try:
			message = iso.getNetworkISO(False) 
			s.send(message)
			print 'Sending ... %s' % message
			ans = s.recv(2048)
			print "\nInput ASCII |%s|" % ans
			isoAns = ISO8583()
			isoAns.setNetworkISO(ans,False)
			v1 = isoAns.getBitsAndValues()
			for v in v1:
				print 'Bit %s of type %s with value = %s' % (v['bit'],v['type'],v['value'])
					
			if isoAns.getMTI() == '0810':
				print "\tThat's great !!! The server understand my message !!!"
			else:
				print "The server dosen't understand my message!"
			
		except InvalidIso8583, ii:
			print ii
			break	
		
		time.sleep(timeBetweenEcho)

		
		
print 'Closing...'		
s.close()