Short Message Peer to Peer (SMPP) is an open, telecommunications industry protocol for exchanging text
messages (SMS) between short message service centers (SMSC) and External Short Messaging Entities (ESMEs).
The protocol is often used for connecting to SMS centers in order to send messages to mobile devices.
OpenSMPP is an open source Java library designed to provide an API for developing ESMEs and Messaging Gateways.
This post contains code snippets that demonstrate the most common operations that can be done with the help of
the OpenSMPP library.
Binding
Connect your application to SMSC by sending a bind request:
Check the alive status of the other party (can be sent both by SMSC and ESME):
12345678
try{finalEnquireLinkrequest=newEnquireLink();log.info("Enquire Link request "+request.debugString());finalEnquireLinkRespresponse=session.enquireLink(request);log.info("Enquire Link response "+response.debugString());}catch(Throwablee){e.printStackTrace();}
Sending an SMS message
Send an SMS message through an SMSC:
12345678910111213141516171819202122232425262728
try{finalSubmitSMrequest=newSubmitSM();request.setServiceType(serviceType);request.setSourceAddr(createAddress(senderPhoneNumber));request.setDestAddr(createAddress(recipientPhoneNumber);request.setShortMessage(messageText);request.setScheduleDeliveryTime(deliveryTime);request.setReplaceIfPresentFlag((byte)0);request.setEsmClass((byte)0);request.setProtocolId((byte)0);request.setPriorityFlag((byte)0);request.setRegisteredDelivery((byte)0);request.setDataCoding((byte)0);request.setSmDefaultMsgId((byte)0);finalSubmitSMRespresponse=session.submit(request);log.info("Submit response "+response.debugString()+", message id "+response.getMessageId());}catch(Throwablee){e.printStackTrace();}privatestaticAddresscreateAddress(Stringaddress)throwsWrongLengthOfStringException{AddressaddressInst=newAddress();addressInst.setTon((byte)1);// national tonaddressInst.setNpi((byte)1);// numeric plan indicatoraddressInst.setAddress(address,Data.SM_ADDR_LEN);returnaddressInst;}