有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在连接到internet时使用HSPA调制解调器发送SMS

我正在开发一个Java应用程序,使用USB调制解调器发送短信(我的是华为E173)。我尝试了SMSLib,它的示例代码成功地发送了sms。但当它连接到互联网时,它给出了一个例外

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)

当手机连接到互联网时,有没有办法发送短信?我是否必须通过Java应用程序本身建立连接?如果是,如何建立连接

编辑:这是我发送短信的完整代码(从smslib.org下载,我更改了SMSC号码和发件人号码)

// 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();
                }
        }
}

共 (1) 个答案

  1. # 1 楼答案

    如果调制解调器正用于“连接到Internet”,则已在进行电话呼叫。你不能用它拨打第二个号码来发送短信。可能的解决办法:

    1. 使用其他方法连接到internet,释放调制解调器
    2. 获得第二条电话线和第二个调制解调器
    3. 使用“电子邮件到短信”服务,改为通过互联网上的电子邮件发送信息。以美国电话电报公司为例,;T您可以向[电话号码]@txt发送电子邮件。att.net向手机发送短信

    如果您试图调试通过调制解调器发送SMS的程序,则选项1或2可能是唯一的解决方案