Re: Deadlock situation while reading from sockets
From: javastudent (neelima1_at_comcast.net)
Date: 08/02/04
- Next message: Tony: "Storing a dynamically created PDF file in memory and storing it to a blob field in a database"
- Previous message: rangert4: "what is catfax"
- In reply to: Chris Rohr: "Re: Deadlock situation while reading from sockets"
- Next in thread: IchBin: "Re: Deadlock situation while reading from sockets"
- Reply: IchBin: "Re: Deadlock situation while reading from sockets"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Tony: "Storing a dynamically created PDF file in memory and storing it to a blob field in a database"
- Previous message: rangert4: "what is catfax"
- In reply to: Chris Rohr: "Re: Deadlock situation while reading from sockets"
- Next in thread: IchBin: "Re: Deadlock situation while reading from sockets"
- Reply: IchBin: "Re: Deadlock situation while reading from sockets"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|