Beispiel #1
0
 def recv(self, show_trace=True):
     """
     """
     data = self.sock.recv(4096)
     if show_trace:
         trace('<< {} bytes received: '.format(len(data)), data)
     return data
Beispiel #2
0
    def send(self, data):
        """
        """
        self.data = self.header.encode('latin') + data
        self.data = struct.pack("!H", int(str(len(self.data)), 16)) + self.data
        self.sock.send(self.data)

        trace(title='>> {} bytes sent:'.format(len(self.data)), data=self.data)
Beispiel #3
0
 def send(self, response, client_name=None):
     """
     """
     response_data = response.build()
     self.conn.send(response_data)
     trace(
         '>> {} bytes sent to {}:'.format(len(response_data), client_name),
         response_data)
     print(response.trace())
Beispiel #4
0
 def recv(self):
     """
     """
     data = self.sock.recv(4096)
     if len(data) > 0:
         trace(title='<< {} bytes received: '.format(len(data)), data=data)
         return data[2:]
     else:
         return None
Beispiel #5
0
 def recv(self, client_name=None):
     """
     """
     data = self.conn.recv(4096)
     if len(data):
         trace(
             '<< {} bytes received from {}: '.format(
                 len(data), client_name), data)
         return data
     else:
         self.conn.shutdown(socket.SHUT_RDWR)
         print('Client disconnected: {}'.format(client_name))
         raise IOError
Beispiel #6
0
def main(s):
    while True:
        conn, addr = s.accept()
        print('Connected client: ' + addr[0] + ':' + str(addr[1]))

        while True:
            try:
                data = conn.recv(4096)
                trace('<< {} bytes received: '.format(len(data)), data)

                Len = struct.unpack_from("!H", data[:2])[0]

                if Len != len(data) - 2:
                    print("Invalid length {0} - {1}".format(
                        Len,
                        len(data) - 2))
                    conn.close()
                    continue

                IsoMessage = ISO8583(data[2:], IsoSpec1987BPC())
                IsoMessage.Print()

                IsoMessage.MTI(get_response(IsoMessage.get_MTI()))

                IsoMessage.Field(39, 1)
                IsoMessage.FieldData(39, '000')
                IsoMessage.Field(2, 0)
                IsoMessage.Field(35, 0)
                IsoMessage.Field(52, 0)
                IsoMessage.Field(60, 0)

                IsoMessage.Print()
                data = IsoMessage.BuildIso()
                data = struct.pack("!H", len(data)) + data

                conn.send(data)
                trace('>> {} bytes sent:'.format(len(data)), data)

            except KeyboardInterrupt:
                print('Exit')
                s.close()
                sys.exit()
Beispiel #7
0
 def send(self, data):
     """
     """
     self.sock.send(data)
     trace(title='>> {} bytes sent:'.format(len(data)), data=data)
Beispiel #8
0
 def send(self, data, show_trace=True):
     """
     """
     if show_trace:
         trace('>> {} bytes sent:'.format(len(data)), data)
     return self.sock.send(data)