juks / iso-8583-socket-queue

ISO 8583 gateway
MIT License
194 stars 111 forks source link

Send mesage to external upstream without httpclient #31

Closed scalpovich closed 5 years ago

scalpovich commented 6 years ago

Hi Igor, Hope you're doing well. i use SQ now it's really amazing. Thanks How can i send a message to an external upstream server without a client connect. For example i use SQ to connect to a upstream server. In specs of this server.. at every connection the upstream server must send to me (here SQ) a 0800 message and i should response automaticaly after make some verification by 0810 Actually when i receive the request 0800 from upstream , SQ log error as ISO host send data with no client. The concerned upstream server connection specifications describe:

  1. Socket must send 0800 to upstream server
  2. upstream server response 0810 and automatically send 0800 with an additionnal data (DE48)
  3. SQ must verify the value of the additionnal data (DE48) and send a 0810 as response with responseCode 0 and must send automatically new 0800
  4. After this exchange done correctly , the upstream server it ready to receive and authorize transactions request from SQ client Can you Assist please
shoaibjdev commented 6 years ago

Hi,

If i remember correctly, this error " ISO host send data with no client" happens when TID (Terminal Id) is expected in the message. By default SQ works in a way that it binds the socket to a specific terminal which is of course right in terms of POS or ATM transactions where in at a time only one user can transaction from a specific terminal. Hence it expects all requests to have this TID field present which is DE41.

Now if you can verify if the 0800 messages which you are receiving from upstream does it contain DE41? Usually it won't as its not required for network messages.

Solution would be to specify not to use TID (DE41) while starting up the SQ as it's available as parameter.

shoaibjdev commented 6 years ago

You can specify this under queueMessageKeyFields (default: '11,41'), so you can remove 41 while starting up SQ as below

Example - node socketQueue.js --upstreamHost=X.X.X.X --upstreamPort=54321 --listenPort=2100 --listenHttpPort=2110 --vv --logFile=log.txt --queueMessageKeyFields=11

Or, Alternatively you could start SQ specifying queueLockTerminal=false so that SQ queues doesn't lock to a terminal.

Example - node socketQueue.js --upstreamHost=X.X.X.X --upstreamPort=54321 --listenPort=2100 --listenHttpPort=2110 --vv --logFile=log.txt --queueLockTerminal=false

scalpovich commented 6 years ago

Hi shoaibjdev , Thanks for your revert. About the TID i remove from parameter.js and i just let DE11 (Stan) , waiting to create a logic to ignore this DE for network messages. My real request it's looking for kind of logic that's automatically send a 0800 request when SQ connected to the upstream and some others message for authentication by himself to the upstream server before Http client or any SQ client make payment auth request

juks commented 6 years ago

Hi!

There is an "Upstream Echo" event: https://github.com/juks/SocketQueue/blob/1b172de810bb928516b511b4fe81b0ae7e0751ac/lib/iso8583/lib/logic/smartVista.js#L103

It is called every time upstream send a 0800 packet to SQ: https://github.com/juks/SocketQueue/blob/1b172de810bb928516b511b4fe81b0ae7e0751ac/lib/socketServer/lib/upstream.js#L253

The thing is you can always tell if the 0800 message is addressed to SQ since it is not a response but a request. How would you like to know if 0810 message does not belong to any client?

Do you mean SQ should own it's own terminal number?

There is a method that is called right after SQ connects to an upstream: https://github.com/juks/SocketQueue/blob/1b172de810bb928516b511b4fe81b0ae7e0751ac/lib/socketServer/lib/upstream.js#L123.

You can add your own code that sends a message to the upstream. But still the question will be: how to process the upstream response in a proper way

scalpovich commented 6 years ago

Thanks for your revert Igor. Got it. i just overwrite the replyUpstreamEcho to auto reply to upstream . But in my case ,before anythings else it(s will be connection between SQ and Upstream server , no SQ client . After SQ connected to the Upstream server, for connect authentication between the upstream server and SQ, SQ must send first 0800 echo test to upstream . In response upstream send 0810 to approuved or not . Then SQ should send echo request 0800 each 5min to maintain the connection otherwise upstream server will disconnect SQ immediatly. In summary, how to send a 0800 packet to external Uptream server just each 5min ?. Thanks

@juks : Do you mean SQ should own it's own terminal number? --- No cause it's just for network messages (0800 - 0810) no need terminal number.

@juks : The thing is you can always tell if the 0800 message is addressed to SQ since it is not a response but a request. How would you like to know if 0810 message does not belong to any client? -- R: In my logic, any SQ http or raw client can't send network message (0800/0810). this kind of message will be exchange just between SQ socket and upstream server (as interface to interface).

juks commented 6 years ago

To send a 0800 packet to an upstream every 5 minutes you need to set up a javascript timer.

scalpovich commented 6 years ago

Get it. below code:

var echoTestTimout = 300000;
 if (typeof parent.logic.replyUpstreamEcho === 'function') {
           var rp = parent.logic.replyUpstreamEcho(p);
            setTimeout(function() { 
                 dd('Sent echo test request to Upstream ..../5min' , 'verbose');
            this.write(rp.getMessage({
              staticHeader: global.c['useStaticHeader'],
              lengthHeader: global.c['useLengthHeader']
            }));
            }.bind(this)
              , echoTestTimout);

Thanks for your help. Really appreciate