在smslib

时间:2016-10-15 15:56:24

标签: java smslib

我的代码仍在运行,我可以发送消息并等待消息发送完毕。发送消息的持续时间大约是10秒,这对我不利,因为我的程序需要1秒间隔才能发送下一条消息。看看澄清问题。

  

msg4 - > msg3 - > msg2 - > MSG1

msg4,msg3和msg2仍在等待msg1发送/失败。

这是代码 sendMessage.java

    public void doIt(String mobile_number, String message) 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.com5", "COM5", 921600, "", "");
            gateway.setInbound(true);
            gateway.setOutbound(true);
            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();



            OutboundMessage msg = new OutboundMessage(mobile_number, message);
            Service.getInstance().sendMessage(msg);

            System.out.println(msg);
            System.out.println("Now Sleeping - Hit <enter> to terminate.");
          //  System.in.read();
            Service.getInstance().stopService();
    }

在我的 main.java

for(int i=0; i<4; i++) {
  new sendMessage().doIt("09483221***","This is the message");
  Thread.sleep(1000);
}

第一条消息已成功发送,但第二条消息未发送。 如何让这些等到第一条消息发送完毕?

1 个答案:

答案 0 :(得分:0)

一旦发送第一条消息,您的端口将无法用于下一条短信,这就是为什么您无法发送第二条短信 解决方案一旦发送你的第一个短信终止端口并发送第二个短信