• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

socket operation

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,

how to set the timeout for the operation?
my question is i have send a request to the server and
waiting for resonse. how to come out from that and continuew my operation
if the server is not responding.

How do you prevent Java from hanging on socket = new Socket(addr, port) line if the machine on the other end is not responding?

Is this possible in Java?

Thanks, Otis
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chennarao,

I guess you cannot do that in one step. But you can break it up as such

int timeOut = 10;
int portNumber=80;
Socket socket = new Socket();
socket.connect(new InetSocketAddress("www.yahoo.com",portNumber),timeOut);
 
Chennarao Marvatu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for ur reply ...

in my case i am successfully connected with servre with
the socket and waiting for some response from the server
if the server is failed OR some other problem for the server
i should come out ..how this will possible
chennarao
 
Premil Jacob
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess since you are creating a TCP/IP connection , if any one of the end points breaks down the connection will be broken automatically giving you an Exception.

So if your server crashed while u were waiting for some data from the server, your connection will be broken. So you need only worry about how to handle the exception. Does that make sense???
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread belongs in our Sockets and Internet Protocols forum. I'll move it there for you.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic