java sockets problem

L

Leo

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
 
T

Tor Iver Wilhelmsen

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?

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.
 
S

Steve Horsley

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top