TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.54k stars 2.58k forks source link

Error Host is unresolved: SmartBox11160899 #775

Closed PhuongNguyenETIT closed 6 years ago

PhuongNguyenETIT commented 6 years ago

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Debug log (for bugs)

Context

Your Environment

PhuongNguyenETIT commented 6 years ago

I use the connected URI("ws://192.168.4.1:3232") to the server. But when I use DNS URI("ws://namedns:3232"), I can not connect to the server. Can anyone help me?

8databit commented 6 years ago

What are you trying to do? Are you trying to approach another device over the internet or locally?

If over the internet, make sure you portforward the right ports for the server to listen too and make sure the device your approaching is not blocking anything on that port.

PhuongNguyenETIT commented 6 years ago

Thank you, 8databit. I'm making a connection from android application to WiFi esp8266 via DNS registered LAN. When I do through IP address then the connection is to WiFi, but when replaced by DNS is not connected to be. `private void ConnectControl(){ URI uri; try { uri = new URI("ws://SmartBox11160899:3232"); } catch (URISyntaxException e) { e.printStackTrace(); return; } client = new WebSocketClient(uri) { @Override public void onOpen(ServerHandshake handshakedata) {

        }

        @Override
        public void onMessage(String message) {
            final String payload = message;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {

                }
            });
        }

        @Override
        public void onClose(int code, String reason, boolean remote) {

        }

        @Override
        public void onError(Exception ex) {

        }
    };
    client.connect();
}`
marci4 commented 6 years ago

Have you tried to resolve the dynamic hostname with something like this? https://stackoverflow.com/questions/15788453/resolving-ip-address-of-a-hostname#15788605

8databit commented 6 years ago

I think marci's answer should work. Maybe URI ("ws://") is not hinting to look locally to resolve the name to an IP.

Marci is telling you to parse the domain to an IP first and than use the IP adress to connect.

marci4 commented 6 years ago

And it could also be that your system dns lookup server really cannot look up this dynamic hostname (e.g. wrong configuration)

PhuongNguyenETIT commented 6 years ago

thanks everyone. you know mDNS in esp8266. I tried to connect from app to esp8266 with mDNS registered, but not connected to it

marci4 commented 6 years ago

Is this non library related issue solved for you?

marci4 commented 6 years ago

No feedback. Closing issue!

Best regards, marci4