Communications
Java API for Kannel SMS/WAP gateway
We are proud to present Java API for Kannel. You can use the API to :
- Send SMS to a single recipient
- Send SMS to multiple recipients (bulk SMS)
- Send SMS with priority
- Send WAP Push message to a single recipient
- Configure send rate (SMS/Second)
Below is an example use of the API
public static void main(String[] args) { SMSManager smsManager = SMSManager.getInstance(); // We can change the prefetch size of the background worker thread smsManager.setSmsMessagesPrefetchSize(30); // We can change the send SMS rate smsManager.setSmsMessagesSendRate(65); try { // Send SMS to a single destination smsManager.sendSMS("localhost", "13013", "foo", "bar", "sender_mobile_number", "receiver_mobile_number", "the_message"); // Send SMS to a single destination with a specific priority and // send rate smsManager.sendSMS("localhost", "13013", "foo", "bar", "sender_mobile_number", "receiver_mobile_number", "the_message", SMSManager.MESSAGE_PRIORITY_3); // Send SMS to multiple recipients List<string> recipientsGroupA = new ArrayList<string>(); recipientsGroupA.add("receiver_mobile_number_1"); recipientsGroupA.add("receiver_mobile_number_2"); recipientsGroupA.add("receiver_mobile_number_3"); recipientsGroupA.add("receiver_mobile_number_4"); recipientsGroupA.add("receiver_mobile_number_5"); smsManager.sendSMS("localhost", "13013", "foo", "bar", "sender_mobile_number", recipientsGroupA, "the_message"); // Send SMS to multiple recipients with a specific priority and // send rate List<string> recipientsGroupB = new ArrayList<string>(); recipientsGroupB.add("receiver_mobile_number_1"); recipientsGroupB.add("receiver_mobile_number_2"); recipientsGroupB.add("receiver_mobile_number_3"); recipientsGroupB.add("receiver_mobile_number_4"); recipientsGroupB.add("receiver_mobile_number_5"); smsManager.sendBulkSMS("localhost", "13013", "foo", "bar", "sender_mobile_number", recipientsGroupB, "the_message", SMSManager.MESSAGE_PRIORITY_7); // Send a WAP Push request to a single mobile recipient smsManager.sendWAPPush("localhost", "8080", "receiver_mobile_number", SMSManager.WAP_PUSH_RECEIVER_TYPE_MOBILE, "the_message", "http://localhost", 3); } catch (Exception ex) { ex.printStackTrace(); } // Stops the background worker // smsManager.stopSMSManagerWorker() }
The API is hosted on Sourceforge. You can download it from here
Any comments are most welcome!
Have Fun!
Justin
Related articles :
- Kannel encoding clarifications
- Java API for Kannel SMS/WAP gateway v 1.0.1 released
- Java API for Kannel SMS/WAP gateway v 1.0.2 released
hey i had recently used ur api and it worked fine. my Q is does ur api receive msgs from kannel
Hello biruk,
Unfortunately the current version of our Kannel API supports only “send” functionality.
so any suggestion as to what i should do to receive sms ?
hello biruk,
i tried to run code but following error is shown
“java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)…..”
do i have to put some ip address at place of localhost or something else?
Hi,
i have tried this example didn’t work,..
in port which number have to give… and from number is message center number or mobile no
this code is giving the below error… please help me…
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:357)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:128)
at sms.SMS.main(SMS.java:22)
Hi Byron,
im newbie in kannel, can you send me instruction on how you setup kannel and your configuration. or you just run on the default configuration.
Thanks
I tried the Kannel API to send SMS, am getting the below error, could you please help on this.
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:852)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:718)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:357)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:128)
Hey there, thats cool stuff. good work to you and those who built the library
please let me know what are the requirements of this application
how do i configure my eclipse after adding this code?
I get this error when I run the sms gateway, please help me out.
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:357)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:128)
at omasungsms.OmasungSMS.main(OmasungSMS.java:32)
i have the same errror, anybody can help us?
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:357)
at com.javacodegeeks.kannel.api.SMSManager.sendSMS(SMSManager.java:128)
at com.sms.app.senderSms.main(senderSms.java:23)