• Post Reply Bookmark Topic Watch Topic
  • New Topic

In what case Socket will get NULL request?  RSS feed

 
Sky Loi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following codes for Socket to receive request. Seems it got NULL request occasionally.

BufferedReader in =new BufferedReader(new InputStreamReader(socket.getInputStream()));
String input = in.readLine();

I do not know where this NULL request is from.

1. Is it from client request? Seems the client side never send NULL request to this server codes.
2. Is it from server OS, e.g. heartbeat? or KeepAlive request, actually I have setKeepAlive false.
3. Is any case of BufferedReader.readLine() method return NULL? seems it return NULL if the end of the stream has been reached. When will this happens? My client side only sends one line request to this sever codes.

Thank you for the help.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedReader's readLine() methods returns null if there is nothing more to read, like the read methods return -1. So if you get null, that means that everything is read, and nothing will be sent again - the socket is probably closed.
 
Sky Loi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My client request string is always end with a carriage return ('\r'). Then the readline() is supposed not to return NULL. Is there other source to send NULL to my server sockets?

Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!