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 / May 2007

Tip: Looking for answers? Try searching our database.

How to stop a socket when it is connecting to remote?

Thread view: 
JTL.zheng - 16 May 2007 16:04 GMT
in one thread it's:
Global.socket_control = new
Socket(InetAddress.getByName("192.168.1.22"), 1234);

when the IP:192.168.1.22 does not exist, it will take so much time to
wait before throw a "time out exception"
how can I stop this waiting in another thread?

I have try "Global.socket_control.close()"
but it doesn't work because Global.socket_control is null

Thank you very much in advance
SadRed - 17 May 2007 00:01 GMT
> in one thread it's:
> Global.socket_control = new
[quoted text clipped - 8 lines]
>
> Thank you very much in advance

Use connect() timeout instead of using a full constructor.
SadRed - 17 May 2007 04:20 GMT
> in one thread it's:
> Global.socket_control = new
[quoted text clipped - 8 lines]
>
> Thank you very much in advance

Use no-arg Socket constructor and connect() with explicit timeout arg.
JTL.zheng - 17 May 2007 16:38 GMT
thank you very much

but is it other way to stop it?
I mean long time "time out" maybe useful when it's a long distance(is
it?)
Esmond Pitt - 18 May 2007 02:08 GMT
> but is it other way to stop it?
> I mean long time "time out" maybe useful when it's a long distance(is
> it?)

So if you don't want to use a timeout how are you going to decide when
you want to stop it?
Mark Space - 18 May 2007 05:10 GMT
>> but is it other way to stop it?
>> I mean long time "time out" maybe useful when it's a long distance(is
>> it?)
>
> So if you don't want to use a timeout how are you going to decide when
> you want to stop it?

Maybe the user presses the Cancel button?  (I.e., some non-timer
external event...)
JTL.zheng - 18 May 2007 10:57 GMT
> >> but is it other way to stop it?
> >> I mean long time "time out" maybe useful when it's a long distance(is
[quoted text clipped - 5 lines]
> Maybe the user presses the Cancel button?  (I.e., some non-timer
> external event...)

Yes, I want to provide a "Cancel" button to stop waiting when it's
trying to connect to remote.
how can I do with this "Cancel" button?
Esmond Pitt - 19 May 2007 06:52 GMT
> Yes, I want to provide a "Cancel" button to stop waiting when it's
> trying to connect to remote.
> how can I do with this "Cancel" button?

Try

    socket = new Socket();
    socket.connect(...);

That way there is an existing socket object for the cancel button to
close, whereupon 'Any thread currently blocked in an I/O operation upon
this socket will throw a SocketException.'
JTL.zheng - 21 May 2007 16:50 GMT
> Try
>
>         socket = new Socket();
>         socket.connect(...);

Thank you very much
It works!
: )


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.