Re: Deadlock situation while reading from sockets

From: javastudent (neelima1_at_comcast.net)
Date: 08/02/04


Date: 1 Aug 2004 15:27:49 -0700

Chris Rohr <cjrohr@verizon.net> wrote in message news:<OAZOc.5163$Je5.4308@nwrddc03.gnilink.net>...
> When the client connects to the socket it only writes the one time then
> waits, so you can use the BufferedReader to read all of the data on the
> socket. Each communication from the client has a new socket, so you
> don't have to maintain a connection and wonder how much data is being
> sent. When the socket is flushed to the server, it will append the eof
> to the stream. Hopes this helps at all.

Thanks for your reply. I really appreciate it.

What method in the BufferedReader class can I use to read all the data
on the socket? Here are the methods I looked at.

1. readLine(): Looks like this method waits till it receives an end of
line, or the socket connection is closed.
2. read(char[] cbuf, int off, int len): Reads only specified number of
bytes, so it works as long as we specify at least as many bytes as
the client sent.

Thank you.

>
> -C
>
> javastudent wrote:
> > Hi,
> >
> > I am implementing a server that reads for socket connections at a
> > port, and processes the socket on a separate thread. We do not control
> > the client implementation. Here is the scenario.
> >
> > 0. Client connects to the socket.
> > 1. Client writes to the socket.
> > 2. Server reads from the socket.
> > 3. Client waits for the response on the socket
> > 4. Server writes to the socket.
> > 5. Socket is closed.
> >
> > Incoming request on the socket is not guaranteed to be terminated with
> > any particular sequence of characters. How does the server know how
> > many bytes to read, and when to stop reading?
> >
> > Here are couple of things I tried.
> >
> > 1. readln on a buffered reader on the server side would block till it
> > receives the "eol" character.
> > 2. I have tried reading x number of characters at a time, and thought
> > if number of characters read are less than the attempted number of
> > characters to read (or the read method returns -1) then read all the
> > data sent by the client. This works if the attempted characters to
> > read initially, are greater than the number of characters sent by the
> > client, but not if it is the other way.
> >
> > I have used BufferedReader, and the PrintWriter classes.
> >
> > I appreciate your help in resolving this issue.
> >
> > Thanks.



Relevant Pages

  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #3]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... kernel socket family. ... presentation side is left to the client. ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #2]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • Re: How do I tell an object to free up an owned object from thta object itself?
    ... I tested running a sequence of connect/disconnect from the client ... client address for those connections that were active. ... In the ClientConnect event I create a handler object for processing ... >Socket is in fact a TServerClientWinSocket which acts as a end-connection ...
    (comp.lang.pascal.delphi.misc)
  • Re: question about class Socket
    ... run the following code, the client send a test string, but it doesn't ... // State object for receiving data from remote device. ... // Client socket. ...
    (microsoft.public.dotnet.framework)