How to receive SMS through nowsms gateway Using Java program

How to receive SMS through nowsms gateway Using Java program SearchSearch

SMS & MMS Technical Forum » NowSMS Support - SMS Issues (Product Support Only) » Archive through June 24, 2009 » How to receive SMS through nowsms gateway Using Java program « Previous || Next »
Author Message
Imraj sk
New member
Username: Imraj

Post Number: 4
Registered: 12-2008
Posted on Thursday, December 11, 2008 - 05:09 pm:   

Hi can any one send me the java code to receive sms through now sms gateway using java program. Iam able to receive that using web interface of the Nowsms gateway.But i want to achieve that using some java program.Using 2-way option we can receive the sms but i need a java program to achive this..
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 327
Registered: 08-2008
Posted on Friday, December 12, 2008 - 09:02 pm:   

When NowSMS receives an SMS message, it can then either connect to an HTTP URL to process the message, or it can run a local command to process the message.

Since I'm not a Java expert, let me explain what the above means, and then we'll relate it back to Java.

To pass the message to an application over HTTP, you'd define a 2-way command with a URL of something like http://server/path?sender=@@SENDER@@&text=@@TEXT@@

Let's say that you received an SMS message from "123456789" with text of "test message".

NowSMS would issue the following 2-way command:

http://server/path?sender=1234567890&text=test+message

An HTTP server application would be able to pass the "sender" and "text" variables to obtain the details about the received message.

If you're building this in Java, you'd probably create a Java servlet on your web server to process this received message.

Obviously, you'd want to test your servlet with simple URL request examples like my example above ... before you went and activated it as a 2-way command.

Alternatively, you could write a simple Java class that ran outside of a web server. In this case, NowSMS could launch the Java to run the command each time a message was received.

To accomplish this, you'd need to write a Java class that you could run from a command line like this:

java c:\checksms.class +447777777777 "test message"

Assuming that you had such a command, try this as the 2-way command:

C:\WINDOWS\system32\cmd.exe /c java C:\checksms.class @@SENDER@@ "@@FULLSMS@@"

(The above assumes that Windows cmd.exe is located in the c:\windows\system32 directory ... if the Windows directory is elsewhere, modify this command as appropriate to signify the location of cmd.exe.)
PHILIP TEO
New member
Username: Philip_teoph

Post Number: 3
Registered: 02-2009
Posted on Thursday, February 05, 2009 - 01:07 am:   

Just wondering if there already have a working checksms.java program available for testing 2-way sms?

Thanks
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 432
Registered: 08-2008
Posted on Thursday, February 05, 2009 - 03:14 pm:   

Hi Philip,

I haven't seen any examples for receiving ... only sending.

For receiving, the command format is flexible in that you can define your own custom command format in the "2-way" command facility.

For sending, you have to follow the format that NowSMS expects ... so that leads toward having an example.

Essentially, you need to be able to parse command line parameters if you are running from the command line. Or if you are running as a servlet, you need to parse URL parameters.

The exact parameters that are passed varies based upon how you define the 2-way command template.

--
Des
NowSMS Support
Ana Maria Orozco
New member
Username: Anita_maria2

Post Number: 1
Registered: 03-2009
Posted on Wednesday, March 04, 2009 - 10:57 pm:   

im working in something like that. i did it in a laptop (windows vista) with a Sony Ericsson celphone, now im working over a virtual machine (XP) using the same code with a nokia N95, but i got problem retrieving sms from it.
i can send sms from the web interface, but i can see the sms recieved.
any idea?
thanx in advanced
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 547
Registered: 08-2008
Posted on Thursday, March 05, 2009 - 07:09 pm:   

Hi Ana,

Unfortunately, the Nokia N95 (and all Nokia S60 phones) do not support delivering received messages over the GSM modem interface. They can only be used for sending messages.

That's why it worked for you previously with a SonyEricsson phone ... they tend to have a more complete GSM modem implementation (as long as you stay away from the high end models using the UIQ or Windows Mobile interfaces).

--
Des
NowSMS Support
Ana Maria Orozco
New member
Username: Anita_maria2

Post Number: 2
Registered: 03-2009
Posted on Thursday, March 05, 2009 - 09:41 pm:   

Thx!

im gonna try again with a sony ericsson cellphone

regards =)
bytescode
New member
Username: Bytescode

Post Number: 1
Registered: 03-2009
Posted on Thursday, March 19, 2009 - 04:08 am:   

Hi,

In this case I'm trying to send and receive SMS using java (like ana too), using Motorola C650 as gateway (conected with PC, OS XP) and Nokia N81 as sender sms.

I want (with N81) send sms that include tag like REG, KRM, and GET. How to seeting/make script ini java like this, so that server (PC+Motorola C650) using Now SMS can receive the sms that contain that tag (REG,KRM,GET)?

Hope help me. Thx.
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 612
Registered: 08-2008
Posted on Thursday, March 19, 2009 - 04:32 pm:   

Hi,

Have you ever written a Java servlet before?

I've written some simple Java applications before, I've just never written a servlet before. I should learn , as it would make it easier to answer these types of questions.

There are some great examples at servlets.com, at least it's helped me with some of the basics.

In particular, the second example on http://www.servlets.com/jservlet2/examples/ch02/index.html (Example 2.3).

Take a look at the source of Example 2.3. This is a very simple Java servlet example, which looks to see if the "name=" parameter was passed to the servlet, and it uses stores the value of that parameter in a new variable, and makes use of that variable in the script.

That's pretty similar to what you'd be doing writing a Java servlet to process a received message from NowSMS.

In NowSMS, you're going to configure a 2-way command that processes received messages (http://www.nowsms.com/documentation/ProductDocumentation/2_way_sms_support.htm).

For the sake of example, let's say you configure the following command:

http://server/path/receivesms?sender=@@SENDER@@&command=@@SMSPREFIX@@&text=@@SMS @@

receivesms would be a Java servlet running on a web/application server.

Suppose you send a message from phone number 123456789 to the modem with the text REG XYZ.

NowSMS is going to issue the following command when it processes the received message:

http://server/path/receivesms?sender=1234567890&command=REG&text=XYZ

For your servlet to parse the "sender" parameter, you would call req.getParameter("sender") ... for the "command" parameter, you would call req.getParameter("command") ... etc.


If you want to return a direct response to the sender, use the following code:

res.setContentType("text/plain");
out.println("This is my response");

I hope that helps. If I can possibly find the time, I'd like to write up a more complete example, but this should be enough to get you started.

--
Des
NowSMS Support
Ana Maria Orozco
New member
Username: Anita_maria2

Post Number: 3
Registered: 03-2009
Posted on Thursday, March 19, 2009 - 04:44 pm:   

Hi, thanks for all the answers.

I wrote a PHP script which helpme process the sms from NowSMS.
Then I send the the text via TCP sockets, to a java program (main server in my case).

SMS----> [NowSMS] ---> PHP(local webserver) --> Java server

Here are the codes:
PHP:
--------------------------
<?php
header ("Content-Type: text/plain");

echo "ok \n";

if (isset($_REQUEST['sender'])) {
if (isset($_REQUEST['text'])) {
echo "Mensaje : " . $_REQUEST['text'];
echo "\n";
echo "Sender : " . $_REQUEST['sender'];
echo "\n";
// CONNECTING TO JAVA SERVER

$server="127.0.0.1";
$puerto=8888;
$conec= fsockopen($server,$puerto);


if(!conec) {
echo ("\r\n Can't connect to server. \r\n");
} else {




$cad = $_REQUEST['text'] .";" ;
echo "sms: " .$cad;


if(!fputs($conec,$cad))
{
echo "Impossible to send data";
exit;
}


fclose($conec);
}




}
else {
echo "ERROR : 'text' There's no parameters \r\n";
}
}
else {
echo "ERROR : 'sender' There's no parameters !\r\n";
}


?>

--------------------------
bytescode
New member
Username: Bytescode

Post Number: 2
Registered: 03-2009
Posted on Friday, April 10, 2009 - 08:20 am:   

@Des :
Thx for your help :-). I'll try it and posting here what will happen. I'm sorry I'm too late to reply this. :-( Thx bro :-)

@ Ana :
Nice source :-)

Login Login / Register Logout Logout Search Last 30 Days Topics Topics