interstar
interstar

Reputation: 27206

Java UnknownHostException When and Why?

I'm trying to post to a website from a Processing Sketch. (Processing is basically Java running in a fancy environment). I'm using this library : http://libraries.seltar.org/postToWeb/ but I don't know if that makes a difference. You can see from the stack trace below that this is just a wrapper for the Java standard library.

Anyway, the important point is that the host "mysite.com" is up and running. I am seeing it from the browser. But when I try to post to it from Java I just get the UnknownHostException appearing.

Given that the site is up. What else might this mean?

The program is currently running inside the Processing environment. Presumably as an Applet.

java.net.UnknownHostException: mysite.com
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.connect(Socket.java:478)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
    at sun.net.www.http.HttpClient.New(HttpClient.java:306)
    at sun.net.www.http.HttpClient.New(HttpClient.java:323)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1014)
    at org.seltar.Bytes2Web.PostToWeb._post(PostToWeb.java:90)
    at org.seltar.Bytes2Web.ByteToWeb.post(ByteToWeb.java:66)
    at experimentPostToWeb.keyPressed(experimentPostToWeb.java:35)
    at processing.core.PApplet.handleKeyEvent(Unknown Source)
    at processing.core.PApplet.dequeueKeyEvents(Unknown Source)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:662)

Upvotes: 0

Views: 1364

Answers (3)

Chris Sim
Chris Sim

Reputation: 4132

You can add -Djava.rmi.server.hostname= -Dremoting.bind_by_host=false to the run script at the server

Upvotes: 0

Indranil
Indranil

Reputation: 11

Proxy problems. Your DNS lookup failure occurs because within the LAN there is nothing registered to that website and the ProxySelector is not using a proxy to reach out to the internet.

Upvotes: 1

Markus
Markus

Reputation: 1303

You could probably just use the link() method of processing http://processing.org/reference/link_.html That way you can verify that processing is actually seeing your page, and from there on you can try to post to it.

Upvotes: 0

Related Questions