// 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 examples.modem;
import org.smslib.*; import org.smslib.modem.*;
public class SendMessage { public void doIt() throws Exception { Service srv; OutboundMessage msg;
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());
srv = new Service(); SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 9600, "SIEMENS", "TC35"); gateway.setInbound(true); gateway.setOutbound(true); gateway.setSimPin("0000"); gateway.setOutboundNotification(outboundNotification); srv.addGateway(gateway);
// Send a message synchronously.支持長短信 msg = new OutboundMessage("13798361236", "消息稱,這一系列戶籍管理制度改革措施,集中解決了三線艱苦地區和部分特殊行業干部職工長期兩地分居問題,實行了農民自理口糧進入集鎮落戶,改革了暫住人口登記管理辦法,啟動并全面推進了小城鎮戶籍管理制度改革;調整了大中城市和西部地區的戶口遷移政策,強化了農村戶口城市化管理。同時,按照“公平對待,搞好服務,合理引導,完善管理”的原則,不斷強化流動人口治安管理、權益保護和服務工作。這改變了長期以來頒發場所治安許可證和特種行業許可證的工作模式,把管理的重點從事前審批調整為事中監督和事后查處并重"); msg.setEncoding(MessageEncodings.ENCUCS2); srv.sendMessage(msg); System.out.println(msg);
System.out.println("Now Sleeping - Hit <enter> to terminate."); System.in.read();
srv.stopService(); }
public class OutboundNotification implements IOutboundMessageNotification { public void process(String gatewayId, OutboundMessage msg) { System.out.println("Outbound handler called from Gateway: " + gatewayId); System.out.println(msg); } }