• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

In what case Socket will get NULL request?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic