Non destructive read of socket



Is it possible to do a non-destructive read on a socket in Java? I
want the functionality similar to the C library recv() using the
MSG_PEEK flag.

More information:
I am implementing an API in Java which needs to send a "are you alive"
application message over a socket. In reply it will get a "I am
alive" message. However there may be another type of message already
waiting which the API must not read. The presence of any message will
be enough for the API call to succeed. The "I am alive" message can
just be discarded if it is read later.

I realize I could buffer the messages internally, but I would prefer
to avoid this if possible owning to the risk of losing a message if
the application is terminated.

.



Relevant Pages

  • Socket recv being slow
    ... There's a server, implemented in Java, that I must create a C++ client for. ... There's already such API implemented in Java ... API equivalent socket call takes less than 30 milliseconds, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Non destructive read of socket
    ... MSG_PEEK flag. ... I am implementing an API in Java which needs to send a "are you alive" ... application message over a socket. ...
    (comp.lang.java.programmer)
  • Re: Non destructive read of socket
    ... I am implementing an API in Java which needs to send a "are you alive" ... Alternatively, I think you can set TCP_KEEPALIVE on the socket, which will handle that at the TCP protocol level, so you don't have to worry about it at the application protocol level. ...
    (comp.lang.java.programmer)
  • Re: simple web programming options
    ... And that I have seen from CGI/FCGI, Java ... PHP seems to provide the best API of ready-to-use ... doing CGIs specifically and scripted access to databases. ... I recommend PHP highest for language. ...
    (comp.programming)
  • Java Network Programming FAQ
    ... Java Network Programming FAQ. ... How can I find out who is accessing my server? ... What are socket options, and why should I use them? ... How does servlet performance compare to applets? ...
    (comp.lang.java.programmer)