• 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

java.net.ConnectException: Connection refused: connect

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

I have a small client-server component.
.i.e. I create a serversocket & then call accept on it (Multithreaded).

I am writing a client which calls the server in a loop. When I call the server, i sometimes get
java.net.ConnectException: Connection refused: connect

Is this due to fact that the client is sending request to the server that is faster that the server can accept connections??

When I slowed down the request by putting some sort of sleep in my client, the occurence of the above exception was less?

for (i = 0; i < 500; i++, j++)
if (j == 50) {
Thread.sleep(1000);
k=0
}
//call server code here
}

What is the limit of the java socket server to accept connections?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your server processing the request on the same thread that accepts connections? That would cause slower performance and might get bad enough to refuse connections. This kind of thing is typical:

You can do even cooler things with NIO.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic