2016-10-15 2 views
0

코드가 여전히 작동 중입니다. 메시지를 보내고 메시지가 전송 될 때까지 기다릴 수 있습니다. 메시지를 보내는 데 걸리는 시간은 모두 약 10 초입니다. 내 프로그램이 다음 메시지를 보내기 전에 1 초 간격을 필요로하기 때문에 나에게 좋지 않습니다. 문제를 명확하게 살펴보십시오. > MSG3 - -> MSG2 -현재 메시지가 처리 중일 때 새 메시지가 나타날 때까지 기다리십시오.

MSG4 MSG1가 전송 될 때까지

MSG4> MSG1이 MSG3 및 MSG2 여전히 기다리고 있습니다/실패했습니다. 여기

main.java 첫 번째 메시지가 성공적으로 전송

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

클래스 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(); 
    } 

코드 하지만, 그래서 두 번째 및 보내지 않은했다 . 첫 번째 메시지를 보낼 때까지 기다리는 방법은 무엇입니까?

답변

0

당신이 첫번째 메시지를 보낼 번 포트가 다음 SMS를 먹으 렴에 사용할 수없는 이유 u는 한 번에 솔루션을 초 SMS 을 보내 귀하의 첫 번째 문자가 포트를 종료하고 두 번째 SMS를 보낼 보낼 수 없습니다

관련 문제