0

I am developing a Java application to send SMS using a USB modem (mine is Huawei E173). I tried SMSLib and its example code succeeded in sending sms. But when it is connected to internet, it gives exception

org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
    at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102)
    at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
    at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
    at org.smslib.Service$1Starter.run(Service.java:277)

Is there any way to send sms while it is connected to internet? Do I have to establish the connection through my Java application itself and if so how?

EDIT: This is my complete code that send sms (downloaded from smslib.org, I changed SMSC number and sender number )

// SendMessage.java - Sample application.
//
// This application shows you the basic procedure for sending messages.
// You will find how to send synchronous and asynchronous messages.
//
// For asynchronous dispatch, the example application sets a callback
// notification, to see what's happened with messages.

package sms;

import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

public class SendMessage
{
        public void doIt() throws Exception
        {
                OutboundNotification outboundNotification = new OutboundNotification();
                System.out.println("Example: Send message from a serial gsm modem.");
                System.out.println(Library.getLibraryDescription());
                System.out.println("Version: " + Library.getLibraryVersion());
                SerialModemGateway gateway = new SerialModemGateway("modem.com3", "COM3", 115200, "Huawei", "");
                gateway.setInbound(true);
                gateway.setOutbound(true);
                gateway.setSimPin("0000");
                // Explicit SMSC address set is required for some modems.
                // Below is for VODAFONE GREECE - be sure to set your own!
                gateway.setSmscNumber("+947500001");
                Service.getInstance().setOutboundMessageNotification(outboundNotification);
                Service.getInstance().addGateway(gateway);
                Service.getInstance().startService();
                System.out.println();
                System.out.println("Modem Information:");
                System.out.println("  Manufacturer: " + gateway.getManufacturer());
                System.out.println("  Model: " + gateway.getModel());
                System.out.println("  Serial No: " + gateway.getSerialNo());
                System.out.println("  SIM IMSI: " + gateway.getImsi());
                System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
                System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
                System.out.println();
                // Send a message synchronously.
                OutboundMessage msg = new OutboundMessage("0094757599108", "Hello from SMSLib!");
                Service.getInstance().sendMessage(msg);
                System.out.println(msg);
                // Or, send out a WAP SI message.
                //OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000",  new URL("http://www.smslib.org/"), "Visit SMSLib now!");
                //Service.getInstance().sendMessage(wapMsg);
                //System.out.println(wapMsg);
                // You can also queue some asynchronous messages to see how the callbacks
                // are called...
                //msg = new OutboundMessage("309999999999", "Wrong number!");
                //srv.queueMessage(msg, gateway.getGatewayId());
                //msg = new OutboundMessage("308888888888", "Wrong number!");
                //srv.queueMessage(msg, gateway.getGatewayId());
                System.out.println("Now Sleeping - Hit <enter> to terminate.");
                System.in.read();
                Service.getInstance().stopService();
        }

        public class OutboundNotification implements IOutboundMessageNotification
        {
                public void process(AGateway gateway, OutboundMessage msg)
                {
                        System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
                        System.out.println(msg);
                }
        }

        public static void main(String args[])
        {
                SendMessage app = new SendMessage();
                try
                {
                        app.doIt();
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                }
        }
}
Peter1
  • 157
  • 1
  • 2
  • 13
  • If the modem is being used to "connect to the Internet" there is already a phone call in progress. You can't then use to dial a second number to send an SMS. Your question is not very clear. Are you really using a dial-up Internet connection? – Jim Garrison Sep 03 '13 at 06:03
  • @JimGarrison Sorry for unclear question it is dial up connection. Thank you and now I understand that I can't use the modem while a call is on progress. But what I want in my application is to send SMS while I am connected to the internet with same modem. Like mobile partner software came up with the modem, how can I develop a java application? – Peter1 Sep 03 '13 at 06:14
  • Either use a different method to connect to the internet or get a second phone line and second modem. – Jim Garrison Sep 03 '13 at 06:15
  • What I really want to do is something like building my own "Mobile Partner" application using java.(That comes up with HSPA dongles, which installs along with dongle's drivers) That application connects to the internet, and simultaneously send/receive sms and voice calls, and USSD codes. – Peter1 Sep 03 '13 at 11:34

1 Answers1

1

If the modem is being used to "connect to the Internet" there is already a phone call in progress. You can't then use it to dial a second number to send an SMS. Possible solutions:

  1. Use a different method to connect to the internet, freeing up the modem
  2. Get a second phone line and second modem
  3. Use an email-to-SMS service and send the message via email over the Internet instead. For example, for AT&T you can send an email to [phone-number]@txt.att.net to send an SMS to a phone.

If you are trying to debug a program that sends SMS over the modem specifically then options 1 or 2 may be the only solution.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190