Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2008

Tip: Looking for answers? Try searching our database.

SocketException: Unable to find reason

Thread view: 
Ravi - 15 Feb 2008 19:42 GMT
http://pastebin.com/m24efe449

Above is a rudimentary socket program.

In the above code I am unable to find why I get SocketException
whenever I run the DateClient? I also tried remove sock.close() from
DateServer.java, but still no help.
Daniele Futtorovic - 15 Feb 2008 20:01 GMT
> http://pastebin.com/m24efe449
>
[quoted text clipped - 3 lines]
> whenever I run the DateClient? I also tried remove sock.close() from
> DateServer.java, but still no help.

Whenever you speak about an Exception, ALWAYS include: type, message,
stacktrace. Together with the stacktrace, you must provide the blocks
and linenumbers of the code which contains the statements referred to by
the stacktrace, insofar as they pertain to your packages.

df.
Knute Johnson - 15 Feb 2008 20:40 GMT
>> http://pastebin.com/m24efe449
>>
[quoted text clipped - 10 lines]
>
> df.

What Daniele said and you are binding two sockets to the same port.

Signature

Knute Johnson
email s/nospam/knute/

     ------->>>>>>http://www.NewsDem

Daniele Futtorovic - 15 Feb 2008 21:54 GMT
>>> http://pastebin.com/m24efe449
>>>
[quoted text clipped - 13 lines]
>
> What Daniele said and you are binding two sockets to the same port.

No, one of them's a ServerSocket. I don't really see anything wrong with
the code. The only source of error I could think of would be to run the
client before the server. We'll see when the OP posts his error description.

df.
Lothar Kimmeringer - 15 Feb 2008 23:47 GMT
>> What Daniele said and you are binding two sockets to the same port.
>
> No, one of them's a ServerSocket.

And event if the sockets are connecting the same port that wouldn't
be a problem and you can even bind two serversockets to the same
port if you really need that. The same is valid for the source-port
of a socket (you need that e.g. for RFC-compliant FTP)

Regards, Lothar
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!

Knute Johnson - 16 Feb 2008 00:07 GMT
>>>> http://pastebin.com/m24efe449
>>>>
[quoted text clipped - 20 lines]
>
> df.

D:

You're right, I misread that.

OP:

I compiled and ran it and it works just fine.  When are you getting the
error?

Signature

Knute Johnson
email s/nospam/knute/

Lothar Kimmeringer - 15 Feb 2008 23:46 GMT
> http://pastebin.com/m24efe449
>
> In the above code I am unable to find why I get SocketException
> whenever I run the DateClient? I also tried remove sock.close() from
> DateServer.java, but still no help.

Still there is a stacktrace missing, but one thing. A PrintWriter
might be buffered, so writing to it and closing the underlying
socket can lead to the effect, that no data runs the wire.

The client tries to read from the InputStream but because of the
closing socket this try will lead to an exception (something
like "connection reset by peer" or similar).

Better flush() the writer/stream and/or close the stream before
closing the socket.

Regards, Lothar
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!

Lew - 16 Feb 2008 01:26 GMT
>> http://pastebin.com/m24efe449
>>
[quoted text clipped - 12 lines]
> Better flush() the writer/stream and/or close the stream before
> closing the socket.

Am I reading the thread right, that the code mixes Writers and InputStreams?

Signature

Lew

Daniele Futtorovic - 16 Feb 2008 01:33 GMT
>>> http://pastebin.com/m24efe449
>>>
[quoted text clipped - 15 lines]
> Am I reading the thread right, that the code mixes Writers and
> InputStreams?

Haven't you read the code an the page the OP linked to?
Lew - 16 Feb 2008 02:00 GMT
>>>> http://pastebin.com/m24efe449
>>>>
[quoted text clipped - 17 lines]
>
> Haven't you read the code an the page the OP linked to?

No.  Why else would I have asked here?

Signature

Lew

Daniele Futtorovic - 16 Feb 2008 02:10 GMT
>>>>> http://pastebin.com/m24efe449
>>>>>
[quoted text clipped - 19 lines]
>
> No.  Why else would I have asked here?

Well, maybe you had read it, but then forgot it, then remembered that
you had read it and realised that you had forgotten it, then read it
again, and then asked anyway just to make a point.

No?
Lew - 16 Feb 2008 03:38 GMT
Lew wrote:
>>>> Am I reading the thread right, that the code mixes Writers and
>>>> InputStreams?

And the answer is ...?

Signature

Lew

Daniele Futtorovic - 16 Feb 2008 04:00 GMT
> Lew wrote:
>>>>> Am I reading the thread right, that the code mixes Writers and
>>>>> InputStreams?
>
> And the answer is ...?

... yes.
Daniele Futtorovic - 16 Feb 2008 04:06 GMT
>> Lew wrote:
>>>>>> Am I reading the thread right, that the code mixes Writers
[quoted text clipped - 3 lines]
>
> .... yes.

While on second thought, I think the answer is rather no. It's mixing
them in the sense that both occur in the code posted; it's not mixing
them in the sense that it uses a Writer to stuff a pipe emptied by an
InputStream /directly/; it's not confusing byte-based API with
char-based API; it's using Writers and Readers but in an acceptable
fashion, gracefully leaving encoding out but that's alright for the
scope of the code which is a, or rather two very little programs... read
the bloody code it will take a few seconds to realise what would take me
a few minutes to write.
Lothar Kimmeringer - 17 Feb 2008 20:24 GMT
> Am I reading the thread right, that the code mixes Writers and InputStreams?

It's not, but even if this would be the case, what should
it matter?

Regards, Lothar
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.