Format Response to Receive TCP API
- This topic has 15 replies, 2 voices, and was last updated 10 years ago by
Bryon Davis.
-
AuthorPosts
-
February 6, 2015 at 7:43 am #6339
fleure fleure
Participanthello,
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.February 6, 2015 at 1:57 pm #6341Bryon Davis
Moderatorfleure,
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
February 16, 2015 at 9:48 am #6355fleure fleure
Participantthank 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.March 2, 2015 at 5:47 am #6647fleure fleure
Participanthello, can you give me please the good format( or an exemple ) of ok response to sent to Receive api.
March 3, 2015 at 4:50 pm #6654Bryon Davis
ModeratorHi 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
March 4, 2015 at 2:52 pm #6655Bryon Davis
Moderatorfleure,
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); } } }
March 5, 2015 at 3:20 am #6656fleure fleure
Participanthello 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.March 5, 2015 at 8:37 am #6657Bryon Davis
Moderatorfleure,
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
March 5, 2015 at 9:54 am #6658fleure fleure
ParticipantOk 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.
March 5, 2015 at 10:29 am #6659Bryon Davis
ModeratorI 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); } } }
March 6, 2015 at 3:22 am #6662fleure fleure
ParticipantGood 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.March 6, 2015 at 12:50 pm #6663Bryon Davis
ModeratorI 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"); } } }
March 9, 2015 at 5:08 am #6664fleure fleure
Participanthello 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.
March 9, 2015 at 10:36 am #6666Bryon Davis
Moderatorfleure,
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
March 9, 2015 at 12:09 pm #6667Bryon Davis
Moderatorfleure,
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
March 13, 2015 at 11:28 am #6797Bryon Davis
ModeratorFleure,
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"); } } }
-
AuthorPosts
- You must be logged in to reply to this topic.