This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Help me !! creat socket! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Help me !! creat socket!" Watch "Help me !! creat socket!" New topic
Author

Help me !! creat socket!

allan lv
Greenhorn

Joined: Mar 29, 2002
Posts: 5
i use jsse/ssl socket!
when i use
socket = (SSLSocket)factory.createSocket(host, port);
if i give a exists host and not used port!
i will wait for more than 10 minute!!!
how can i set timeout, when creatSocket???
Vijayakumar Arya
Ranch Hand

Joined: Jan 27, 2003
Posts: 76
Hi,
You can specify the timeout via invoking the method setSoTimeout(int timeOut), once you create the socket. This functionality is inherited from the java.net.Socket.


Thanks,<p>Vijay<p>The Hand that gives, Gathers.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
An additional bit of information:- the trick is first to create an unconnected Socket with the no-arg factory method and only then to connect it using connect(SocketAddress, timeout).
- Peter
allan lv
Greenhorn

Joined: Mar 29, 2002
Posts: 5
creatSocket(host,port)
only this method will spend more than 10 minute when host exist but port not!!
who can help me set timeout when only when
creatSocket!!!
and i know socket.setTimeOut(),but this method
can do only socket is connectted!!!
Vijayakumar Arya
Ranch Hand

Joined: Jan 27, 2003
Posts: 76
Hi Allan,
You can try what Peter was saying, first create an unconnected socket and then specify the timeout while connecting.
The connect method throws a SocketTimeoutException - if the timeout expires before connecting. There is no need for you to wait for 10 mins.
Specifying the timeout at socket creation is not available. I am not aware why they have not specified the timeout value at creation time.
allan lv
Greenhorn

Joined: Mar 29, 2002
Posts: 5
i use jsse-1_0_3_01-gl!
SocketFactory can not create an unconnected socket !
what can i do?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Help me !! creat socket!