Format Response to Receive TCP API

Home Forums iSMS Format Response to Receive TCP API

Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #6339
    fleure fleure
    Participant

    hello,
    i receive messages from muti modem isms and i try to send response to the multimodem but i am not sur for the good format of response to send.
    can you give me un exemple of response please.
    Fleure.

    #6341
    Bryon Davis
    Moderator

    fleure,
    Looking at the code, for TCP Non-Polling API we are expecting the response to start with “OK” (no quotes). I don’t believe it needs special format like a HTTP response.

    Bryon

    #6355
    fleure fleure
    Participant

    thank you Bryon, but this solution d’ont resolve my probleme. can you give me all the format please ( an exemple of OK response).
    thank you.

    #6647
    fleure fleure
    Participant

    hello, can you give me please the good format( or an exemple ) of ok response to sent to Receive api.

    #6654
    Bryon Davis
    Moderator

    Hi fleure,
    Sorry for the delay, I have been looking into this problem some more. In my testing, I just needed to send “OK” (capital letters without the quotes) and it accepted it. I used a simple python script that created a socket to test with. If I sent a different response it failed.

    I haven’t had a chance to try with java yet.

    Can you copy and paste an example of a failed delivery attempt from the “Receive API Live Log”? This is in the Statistics&Logs -> Log Traces menu. I would suggest omitting any personal data such as names and phone numbers.

    If you prefer, you can create a case in the support portal where it would be easier to attach files.

    Bryon

    #6655
    Bryon Davis
    Moderator

    fleure,
    I was able to create a simple java server program that successfully responds to the iSMS Non-Polling TCP deliveries.

    Here it is:

    import java.io.*;
    import java.net.*;
    
    public class TCPServer {
        
        public static void main(String argv[]) throws Exception
          {
             int port = 6789;
             String recvLine;
             ServerSocket welcomeSocket = new ServerSocket(port);
             System.out.println("TCP Server Starting on Port: " + port);
    
             while(true)
             {
                Socket connectionSocket = welcomeSocket.accept();
                BufferedReader inFromClient =
                   new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
                recvLine = inFromClient.readLine();
                System.out.println("Received: " + recvLine);
                System.out.println("Sending: OK");
                byte[] b = "OK".getBytes();
                outToClient.write(b);
             }
          }
    }
    #6656
    fleure fleure
    Participant

    hello bryon , thank you for you response.
    if you test your code , is the isms still to send you messages or not ?. because i keep getting messages, and logically it should just send me the new messages and not the old to whom I have already answered.

    #6657
    Bryon Davis
    Moderator

    fleure,
    When testing the java code provided with my SF100 v1.51.28 (the SF400 and SF800 should behave the same), my TCP Non-Polling Recv API deliveries were shown as successful in the SF100’s “Receive API Live Log” and were only delivered once.

    If you are still getting the same messages multiple times, then I would suggest making sure you are at the latest firmware (v1.51.28), verify that “Non Polling Receive API Status” is set to TCP in the SMS API menu (HTTP requires a different response), and check what the Receive API Live Log is showing. The Receive API Live log should show if it was considered successful, and if it wasn’t it will show the response it received from your server.

    Bryon

    #6658
    fleure fleure
    Participant

    Ok Byron, I’ll check the modem configuration. but I see in the received sms that the version of the modem is MultiModem iSMS / 1.51.28 it’s just that the authentication is OFF.

    #6659
    Bryon Davis
    Moderator

    I updated the java code to show the entire message received. See Below.

    import java.io.*;
    import java.net.*;
    
    public class TCPServer {
        
        public static void main(String argv[]) throws Exception
          {
             int port = 2040;
             String recvLine = "";
             ServerSocket welcomeSocket = new ServerSocket(port);
             System.out.println("TCP Server Starting on Port: " + port);
    
             while(true)
             {
                Socket connectionSocket = welcomeSocket.accept();
                BufferedReader inFromClient =
                   new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
                String recvData = "";
                while(true)
                {
                    recvLine = inFromClient.readLine();
                    if (recvLine==null)
                        break;
                    recvData += recvLine + "\r\n";
                }
                System.out.println("Received: \r\n" + recvData);
                System.out.println("Sending: OK");
                byte[] b = "OK".getBytes();
                outToClient.write(b);
             }
          }
    }
    
    #6662
    fleure fleure
    Participant

    Good mornig Bryon,
    i chek about the version, it is for version 1.51.28 and the product modem number is SF800-G.
    I’ve noticed is the paramettre (Max Posts Per Post), it must be to have just 1 new message? because in the modem config I have a value of 50.

    is that it is the same configuration that you have . and if you can give me all the configuration that you have in the page (not polling Receive API Configuration).
    Thank you for your help.

    #6663
    Bryon Davis
    Moderator

    I tested the previous java code with my SF800 and noticed two problems.

    First that the Java code was taking a very long time to readline all of the input stream. It took 20 seconds before it would respond with an OK.

    The second issue is that the SF800 wasn’t waiting 30 seconds before timing out. I’m looking into why the SF800 is timing out too quick.

    I also updated the java code to use read() instead of readline() which is much quicker. I test with 47 messages on my SF800 and it still successfully delivered.

    Here is the updated java code:

    import java.io.*;
    import java.net.*;
    
    public class TCPServer {
        
        public static void main(String argv[]) throws Exception
        {
            int port = 2040;
            int msgCount = 0;
             
            ServerSocket welcomeSocket = new ServerSocket(port);
            System.out.println("TCP Server Starting on Port: " + port);
    
            while(true)
            {
                Socket connectionSocket = welcomeSocket.accept();
                BufferedReader inFromClient =
                   new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
    
                msgCount++;
                System.out.println("------------------");
                System.out.println("Msg #: " + msgCount);
                
                char[] inChars = new char[64000];
                inFromClient.read(inChars);
                String recvData = new String(inChars);
                System.out.println("Received: \r\n" + recvData);
                                    
                System.out.println("Sending: OK");
                byte[] b = "OK".getBytes();
                outToClient.write(b);
    
                System.out.println("Done.");
                System.out.println("------------------\n\n");
            }
        }
    }
    
    #6664
    fleure fleure
    Participant

    hello bryon;
    i want to know if after sending the ok response, you receive the list of the same messages or you receive new messages. this is my probleme , if i send the ok response , the isms modem continues to sent me all the liste of sms.
    ( the old messages i have received and the new one), but I want to receive new messages that I have not yet received.

    I want to know also about setting the Max Posts Per Post parameters. What is the value you have set.

    thank you.

    #6666
    Bryon Davis
    Moderator

    fleure,
    Yes, the sms texts were only delivered once if the OK response was successfully received by the SF800.

    Please check the “Receive API Live Log” to see if the Delivery was considered successful by the SF800. If a delivery was considered a failure, the sms texts will be redelivered until it is successful.

    If the “Receive API Live Log” shows the deliveries are failing, the delivery message will help determine what the problem may be. A “failed to connect to TCP server” message may indicate that the response took longer than expected or wasn’t receive. If it receive an incorrect response, it will display the response it received.

    Bryon

    #6667
    Bryon Davis
    Moderator

    fleure,
    I verified that the SF800 firmware currently uses 20 seconds for the timeout value when waiting for a Non-Polling TCP Receive API response. I will increase this to 30 seconds in the next firmware.

    If you are receiving time out or “failed to connect to TCP server” messages in the Receive API Live Log, I can make this change available to you.

    Bryon

    #6797
    Bryon Davis
    Moderator

    Fleure,
    In my testing of the java code I provided I noticed that it was handling special characters correctly. I’ve updated the java code to handle special characters.

    import java.io.*;
    import java.net.*;
    
    public class TCPServer {
        
        public static void main(String argv[]) throws Exception
        {
            int port = 2040;
            int msgCount = 0;
                     
            ServerSocket welcomeSocket = new ServerSocket(port);
            System.out.println("TCP Server Starting on Port: " + port);
    
            while(true)
            {
                Socket connectionSocket = welcomeSocket.accept();
                InputStream inStream = connectionSocket.getInputStream();
                DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
    
                msgCount++;
                System.out.println("------------------");
                System.out.println("Msg #: " + msgCount);
                
                // Create byte buffer, read data, and convert to ISO-8859-1 string
                byte[] inBytes = new byte[64000];
                inStream.read(inBytes);
                String recvData = new String(inBytes, "ISO-8859-1");
                System.out.println("Received: \r\n" + recvData);
                                       
                // Send "OK" response
                System.out.println("Sending: OK");
                byte[] b = "OK".getBytes();
                outToClient.write(b);
    
                System.out.println("Done.");
                System.out.println("------------------\n\n");
            }
        }
    }
    
Viewing 16 posts - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.