0

my code is still working and I can send a message and wait until the message has been sent. The duration of sending a message is all about 10 seconds which is not good for me because my program needs 1 seconds interval before the next message to send. take a look to clarify the problem.

msg4 -> msg3 -> msg2 -> msg1

msg4, msg3 and msg2 are still waiting until the msg1 has been sent/failed.

here is the code 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();
    }

in my main.java class

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

The first message was successfully sent but the second one and so on was unsent. How to make these to wait until the first message has been sent?

MGB C
  • 442
  • 2
  • 7
  • 21

1 Answers1

0

once you send 1st message your port is unavailable to for the next sms thats why u cannot able to send second sms the solution once send your first sms terminate the port and send second sms

Vinu Vish
  • 153
  • 2
  • 16