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 / General / September 2003

Tip: Looking for answers? Try searching our database.

java sockets problem

Thread view: 
Leo - 29 Sep 2003 22:03 GMT
When I create a socket such as Socket sock = new Socket(address, port)
and I pass some garbage value to address field like (123334) or
something like that, the client just hangs up and does not throw any
exceptions or anything. The funny thing is, when the address field is
composed of characters, say I have "123.45.6.adasd" as the address
then java does throw an exception, but if I only have numbers, it does
not. What is going on?

P.S.

This only happens when I compile and run on UNIX. In windows it works
fine, it timesout and throws an exception with both characters and
numbers.

I am using sdk 1.4.1
Tor Iver Wilhelmsen - 29 Sep 2003 23:02 GMT
> When I create a socket such as Socket sock = new Socket(address, port)
> and I pass some garbage value to address field like (123334) or
[quoted text clipped - 3 lines]
> then java does throw an exception, but if I only have numbers, it does
> not. What is going on?

The binary address 123334 is not garbage. It's perfectly legal to use
the "computed" IP number instead of the byte-separated version people
usually use.

For instance, the IP address called 10.0.0.1 is really

(10 * 1<<24) + (0 * 1<<16) + (0 * 1<<8) + 1 = 167772161

However, IPv4 addresses are only 32 bits (4 * 8) so any value larger
than 4294967295 should give an error.

Java should try and resolve any legal address you pass to the Socket
constructor.
Steve Horsley - 30 Sep 2003 18:21 GMT
>> When I create a socket such as Socket sock = new Socket(address, port)
>> and I pass some garbage value to address field like (123334) or
[quoted text clipped - 17 lines]
> Java should try and resolve any legal address you pass to the Socket
> constructor.

Hmm. I didn't know that. So I guess that the reason it doesn't throw an
exception in unix is that the timeout for a tcp connection attempt is
rather longer than in windows, and you're not waiting long enough (several
minutes).

Steve


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



©2009 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.