• 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

HttpServer connection refused?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following snippet of code (based largely on the ubiquitous toy example) accepts connections on the same box, but not from a browser elsewhere on our internal network. (This is all internal IP traffic, so firewall issues should not come into play).

I can telnet to this and get the response from my handler (not included for brevity), but from the server where it's running, and not from my desktop. I simply get "connection refused" or some variant based on the telnet client/browser being used. I tried adding "InetAddress.getLocalHost()" to the constructor of InetSocketAddress, which did change the way the listener looked in "netstat -an" from the 0.0.0.0:8888 to 10.x.x.x:8888. No change!

Changing the Executor for the HttpServer class did not change anything either! Neither did bumping up the connection queue to 128.

Can anybody help?!


 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change to:
 
Michael Murphy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but that did not allow me to connect.

I am able to ping this box from my desktop, but telnet to the listener port from any other box shows "port 8888: connection failed." The listener, of course, now shows the behavoir I was hoping to avoid, only listening on the loopback:

netstat -an | grep 8888 # listener port
tcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN

I was hoping that getting the NIC's routable IP in the listener would work, but it doesn't. I've done that both with hard coding the IP in a String, and the InetAddress.getLocalHost() call.

tcp 0 0 10.n.n.n:8888 0.0.0.0:* LISTEN

I am starting to wonder if Oracle's toy example web server (straight from the Javadoc pages with "null" passed to HttpServer.setExecutor(null) works for ANYBODY connecting from another host, or whether this is some weird iptables issue that is site specific.

Unless somebody can point out an error that I'm making, I will have to try this code on another network and see if this still happens.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Murphy wrote:I am able to ping this box from my desktop,


Ohh, sorry I though you are using only one machine!

Michael Murphy wrote:but telnet to the listener port from any other box shows "port 8888: connection failed."


Well, I sugest not to use telnet, but use browser or any http client to connect.

Michael Murphy wrote:I was hoping that getting the NIC's routable IP in the listener would work, but it doesn't. I've done that both with hard coding the IP in a String, and the InetAddress.getLocalHost() call.

tcp 0 0 10.n.n.n:8888 0.0.0.0:* LISTEN


hmm, in that case I suspect a proxy issue, can you tell your browser to skip the proxy settings for this IP 10.n.n.n
 
Michael Murphy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. It actually turned out to be an 'iptables' rule on the box that was blocking the connection. I am grateful nobody chided me for the SQLite calls which had nothing to do with my question at all (and actually were not used -- was just testing the pure java SQLite jar and forgot to remove it before posting).

For anybody reading this thread, it may be worth noting that on Vista anyway, InetAddress.getLocalHost() returns a String of netbios name/IP address that is not usable for the call, but on Unix/Linux, it seems to return an IP. There is no way to know which one it would use for a multi-homed host (like a DMZ box) so in the context of web server, the listener IP/port should probably come from a properties file.

$0.02

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic