• Post Reply Bookmark Topic Watch Topic
  • New Topic

Client socket pool and reuse  RSS feed

 
raj sekhar
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a pool of sockets for subsequent reuse instead of creating a fresh socket everytime.
I have trouble in re-using the sockets. Am not sure if I am missing anything here but I run into null-pointer on the socket object(though it is not null) when I try to invoke getOutputStream(). This is only on the second use of the same socket.The first send and recv are great.
Please suggest ways or any urls on this topic.
For ref here is the code where I am running into problems.
if (sock !=null) {
printLocal("IMSConnection.STSend():socket not null ");
printLocal("IMSConnection.STSend():connected port = "+
sock.getPort());
printLocal("IMSConnection.STSend():connected host = "+
sock.getInetAddress());
}
tncodePad = stringPad(tncode,' ',8);
try {
try{
out1= new DataOutputStream(sock.getOutputStream());
}
catch (Exception e) {
if ((e.toString()).equals("java.io.EOFException")) {
printLocal("IMSConnection.STSend() EOFException caught");
}
else {
printLocal("IMSConnection.STSend():"+ e.toString());
log.writeToLogWindow(20,"IMSConnection.STSend(): " +
e.toString());
}
}
out2 = new PrintWriter(out1);
out1.writeInt(totalLength); // send total message length
out1.writeShort(prefixLength); //
Thanks
 
raj sekhar
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can somebody answer this please? let me know if you need more info.
Thanks
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace would be a good start. And are you closing socket or stream before trying to reuse it?
- Peter
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!