I have a client which can generate and send SMS message by using SMPP protocol. I can setup on the client side destination address and user, password.
I would like to create a very simple server (listener) which will receive message (without SSL) from client side and write results in a file. I have found a lot of articles on this topic, but they didn't help me.
Could you suggest the best way for solving this issue?
This is a very simple way. Since you have client I assume there is a way to encode/decode bytes into SMPP packet.
public void runServer() throws Exception
{
ServerSocket serverSocket = new ServerSocket(6868);
Socket socket = serverSocket.accept();
while (socket.isBound()) {
byte[] bytes = readBytes(socket.getInputStream()) ;
- encode bytes to smpp
- create smpp response and decode to bytes
socket.getOutputStream().write(bytes);
socket.getOuptutStream().flush();
}
socket.close();
serverSocket.close();
}
private byte[] readBytes(InputStream is) throws Exception
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i ;
while ((i=is.read()) != -1) baos.write(i);
return baos.toByteArray();
}
If you want more bullet proof code, then after server accept you create a worker thread, which runs separately, while server is accepting another connections.