RSmsUcp is a Java[TM] component that can sms messages using the Ucp protocol. The component can establish a connection to a SMSC (Short Message Service Centre) using:
In order to install the component you must:
if you want to use a dial up connection you will also need the Java[TM] Communications API:
if you want to use TCP/IP, no additional libraries are required.
The component includes a high level class called SmsSender which allows you to send sms message without having to deal with the ucp details. This class works in the following way:
1. Using a dial up connection
The following program will send a sms using a dial up connection:
// create object
Modem modem= new Modem();
modem.setPortName("COM3");
modem.dataBits=SerialPort.DATABITS_8; // do not forget to check if the SMSC uses 7 or 8 bits
// open port , initialize and connect
if (modem.openPort()) {
if (modem.initializeModem())
if (modem.dial("900900900")) {// send the sms now using the Modem adapter
SmsSender sender=new SmsSender(modem);
sender.createSMS51("123","456","Hello");
sender.sendMessage();
// close connection
modem.hangup();}
modem.closePort();
}
2. Using a TCP/IP connection
The following program will send a sms using a tcp/ip connection:
// create object
TcpIpAdapter tcp=new TcpIpAdapter();
tcp.connect(ServerAddress,port);
// send the sms now using the tcp/ip adapter
SmsSender sender=new SmsSender(tcp);
sender.createSMS51("123","456","Hello");
sender.sendMessage();
tcp.disconnect();
3. Using low level classes
As an alternative to the SmsSender class you can also create the ucp messages yourself. This has the advantage that you can use all available features. The low level classes can be used as follows:
Example:
// step 1, create message
BasicSubmitMessage currentMessage= new BasicSubmitMessage();
((BasicSubmitMessage) currentMessage).originator=from;
((BasicSubmitMessage) currentMessage).recipient=destination;
((BasicSubmitMessage) currentMessage).alphaMessage=message;
// step 2 , send message
byte[] b=currentMessage.toBytes();
adapter.transmitBytes(b,b.length); // adapter is either modem or tcpip
// step 3 get response
byte[] responseb=adapter.receiveData(UcpMessage.ETX_CHAR,30);if (responseb==null) throw new SmsException("Response is null");
// step 4 process response
currentResponse=UcpMessage.parse(responseb);if (currentResponse==null) throw new SmsException("Could not parse "+ new String(responseb));
if (currentResponse instanceof ResponseMessage) {
if (((ResponseMessage) currentResponse).Response.compareTo("A")==0) System.out.println("Message was sent successfully");
elseif (((ResponseMessage) currentResponse).Response.compareTo("N")==0) System.out.println("Message failed: " + ((ResponseMessage) currentResponse).errorDescription);
else throw new SmsException("Response not recognized "+ new String(responseb));
}
else throw new SmsException("Response message not received : "+ currentResponse.getClass());