General discussion

Locked

What is java.net.Socket...?

By danielr ·
In this paragraph what is java.net.Socket, java.net.DatagramSocket, and java.net.ServerSocket?
The value for SO_TIMEOUT is set by using the setSoTimeout() method, supported by java.net.Socket, java.net.DatagramSocket, and java.net.ServerSocket. ThesetSoTimeout method accepts an int, which is the amount of time in milliseconds allowed before a timeout is encountered (for example, a value of 2000 equals two seconds).

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

What is java.net.Socket...?

by mpdcsup In reply to What is java.net.Socket.. ...

java.net.Socket, java.net.DatagramSocket, and java.net.ServerSocket are classes used in the Java Development Kit.

I'm curious why you are asking though. I wouldn't expect this paragraph to show up as part of an error message -- I'd expect it to appear in documentation. This leads me to wonder what you're *really* asking since you are reading the answer.

Here's something to put you to sleep, though (the paragraphs preceding and following yours).

http://developer.java.sun.com/developer/technicalArticles//Networking/timeouts/index.html

Collapse -

What is java.net.Socket...?

by danielr In reply to What is java.net.Socket.. ...

Im sorry. I said the question in a different way I should of. I already knew they were classes. I need to know there purpose. I went to that page and it was not found. I recieved an e-mail(as I signed up for it) from tech republic wich is where I copied from for the above paragraph. The message I recieved is as follows:

Handling connectivity timeouts with Java, part 2

Yesterday we exposed the problem of network delays between a client and server over the Internet, and today we'll look ata solution to this problem.

JDK 1.1 and above provides a socket option called SO_TIMEOUT. It allows the developer to specify a period of time that, if exceeded in a network delay situation, causes a java.io.InterruptedIOException to be thrown. Once caught, you can then handle the situation however you choose.

The value for SO_TIMEOUT is set by using the setSoTimeout() method, supported by java.net.Socket, java.net.DatagramSocket, and java.net.ServerSocket. The setSoTimeout method accepts an int, which is the amount of time in milliseconds allowed before a timeout is encountered (for example, a value of 2000 equals two seconds).

When the SO_TIMEOUT option is set, any blocking operation will cause this exception to be thrown, effectively handling any case of timeout that's encountered. Consider the following use of setSoTimeout:

mySocket.setSoTimeout(10000);

This line of code will cause the java.io.InterruptedIOException to be thrown after 10 seconds of waiting for receipt of packets from the client (or server). From there, the thread can be killed, ending the connection (and sending a graceful error message). Next time we'll look at a bit of sample code to demonstrate this.

Collapse -

What is java.net.Socket...?

by mpdcsup In reply to What is java.net.Socket.. ...

Okay, lets try this from another approach. Without the value SO_TIMEOUT and a method to set that value (java.net.Socket.setSoTimeout(), java.net.DatagramSocket.setSoTimeout() & java.net.ServerSocket.setSoTimeout()) a java developer would have no way to specify the amount of time to wait for an I/O operation on the network to return -- a read to an unreachable IP address could take a long time to return. The SO_TIMEOUT value lets the developer create a function that reacts more quickly to network inconsistencies.

Try the URL (http://developer.java.sun.com/developer/technicalArticles/Networking/timeouts/index.html) again, but make sure there are no spaces in the address bar when you cut and paste -- TechRepublic inserts formatting characters into these messages that I can't control or overcome.

Bruce

Collapse -

What is java.net.Socket...?

by danielr In reply to What is java.net.Socket.. ...

Thanks, it helped a lot.

Collapse -

What is java.net.Socket...?

by danielr In reply to What is java.net.Socket.. ...

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Software Forums