🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #851

Re: Stream closes the socket

#851
From: Owen Green
Date: Thu, 03 Oct 2002 19:28
60 lines
3598 bytes
"Alexei Akimov" <a_p_akimov@mtu-net.ru> wrote in message
news:3d9c5a6a@newsgroups.borland.com...

> The freeze is occuring on the server exactly at the line where while
> condition is checked:
> while ((currentLine = DataReader.readLine()) != null {
> ***
> }

I which case I find it rather more likely that you haven't got an EOL at the
end of your string. What happens if you change
  requestWriter.write(Text);
to
 requestWriter.printLn(Text);
?

If readLine() gets some data then it will be blocking until it gets an EOL
character or until an end of stream (-1) occurs (say if the peer socket
closed either the stream or the connection), or a socket timeout occurs.

>On the other hand the client starts waiting for server's response
> just after sending the file's content to server. So both the server and
the
> client are waiting for the data from each other and this is the freese. It
> looks like a deadlock.

No, because they're blocking on different entities - so long as /something/
sends some (valid) data before going into a blocking read things should keep
moving.

> > Have you verified that the Response class serializes ok?
> Yes, it implements serializable interface.

Ah, I meant have you actually serialized and subsequently deserialized an
instance (without going over a socket) to verify that it was behaving as
expected? It would have been / still will be, depending on whether it is an
EOL thing or not, a valuble eliminating step in tracking down the cause.

> > What are you doing with respect to threading on the server?
> The processSaveRequest is a member of the ServerThread class which extends
> Thread and it's run method is waiting for client connections:

  <snip>

>         fSocket = fServerSocket.accept();
>         ObjectInputStream requestStream = new ObjectInputStream(
>                 fSocket.getInputStream());
>         processRequest((Request)requestStream.readObject());

This will, of course, limit you to handling one client at a time on that
server socket - if you spawned a thread to perform the handling for each
socket returned by accept() then you could handle many requests
simultaenously.

Also, I would advocate putting the close methods on the socket in a finally
block to ensure that they get called, otherwise you'll be left with unclosed
connections hanging around if an exception is thrown.

hth
Owen
Technical Details
Message-ID: <3d9c9b52$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!news-out.nuthinbutnews.com!propagator2-sterling!news-in-sterling.newsfeed.com!news-in.nuthinbutnews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!newsgroups.borland.com!not-for-mail
References: <3d9af28d$1@newsgroups.borland.com> <3d9b43d4@newsgroups.borland.com> <3d9c31f5@newsgroups.borland.com> <3d9c4372$1@newsgroups.borland.com> <3d9c5a6a@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,79dc1cae35190f2a
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-10-03 14:52:34 PST
From: "Owen Green" <owen@begonefoulmachine.kennulz.demon.co.uk>
Newsgroups: borland.public.jbuilder.java.api
References: <3d9af28d$1@newsgroups.borland.com> <3d9b43d4@newsgroups.borland.com> <3d9c31f5@newsgroups.borland.com> <3d9c4372$1@newsgroups.borland.com> <3d9c5a6a@newsgroups.borland.com>
Subject: Re: Stream closes the socket
Date: Thu, 3 Oct 2002 20:28:56 +0100
Lines: 66
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
NNTP-Posting-Host: 62.253.133.165
Message-ID: <3d9c9b52$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1033673554 62.253.133.165 (3 Oct 2002 12:32:34 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!news-out.nuthinbutnews.com!propagator2-sterling!news-in-sterling.newsfeed.com!news-in.nuthinbutnews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!newsgroups.borland.com!not-for-mail