Git Product home page Git Product logo

Comments (11)

TakahikoKawasaki avatar TakahikoKawasaki commented on July 29, 2024 1

RFC 6455 says "Any status code other than 101 indicates that the WebSocket handshake has not completed". In other words, other HTTP status codes than 101 indicate that the server rejected to talk WebSocket protocol.

Supporting other HTTP status codes than 101 is not a task for a WebSocket client library but a task for a generic HTTP client library. nv-websocket-client is not aiming at becoming a generic HTTP client library.

What behaviors do you expect when an HTTP status code other than 101 is returned from a WebSocket server?

from nv-websocket-client.

TakahikoKawasaki avatar TakahikoKawasaki commented on July 29, 2024

I'm sorry I cannot understand your question. What do you mean by "implement '101 Switching Protocols'" ?

from nv-websocket-client.

amallo avatar amallo commented on July 29, 2024

Hi sorry my question was not clear.

when trying to connect to my server I have this error "The status code of the opening handshake response is not '101 Switching Protocols".

On your home page it is said : "HTTP response codes other than "101 Switching Protocols" from a WebSocket endpoint are not supported",

will you support other response code in the future ? My previous library could connect properly so I guess that this 'error' depends on the way you handle connection.

from nv-websocket-client.

smilecs avatar smilecs commented on July 29, 2024

though curently I have just tried my app thats using the library and its not connecting to my webserver "The status code of the opening handshake response is not '101 Switching Protocols'" I dont know if the issue is from client or server

from nv-websocket-client.

TakahikoKawasaki avatar TakahikoKawasaki commented on July 29, 2024

In most cases, a client application is to blame for other HTTP status codes than 101. For example, 404 (Not Found) is returned when a client application specified a wrong URL. A server is to blame only when a 5xx status code is returned.

For other status codes than 101, "the semantics of HTTP still apply" (RFC 6455, 1.3. Opening Handshake). If you receive a status code other than 101, it's not a WebSocket problem but a normal HTTP problem.

from nv-websocket-client.

amallo avatar amallo commented on July 29, 2024

Thanks for your reply !

Problem is : my previous socket library connects successfully to my SSL websocket server but yours can't connect to the server, am I missing something ?

Here is my code :

String host = "wss://myserver.com";
mWebSocketFactory = new WebSocketFactory();
websocket = mWebSocketFactory.createSocket(host, 5000);
websocket.setPingInterval(30 * 1000);
websocket.setAutoFlush(true);
websocket.addListener(...);
websocket.connectAsynchronously();

from nv-websocket-client.

amallo avatar amallo commented on July 29, 2024

I found my error !

I missed the url port now it works. Strange because there were no need my with previous library, sounds like a redirection problem.

Thanks for your time ! I will test your library now !

from nv-websocket-client.

TakahikoKawasaki avatar TakahikoKawasaki commented on July 29, 2024

Sorry, redirection (3xx) is not supported although I think it would be better to support it.

from nv-websocket-client.

TakahikoKawasaki avatar TakahikoKawasaki commented on July 29, 2024

Released a new version, 1.19.

Since the new version, connect() method throws OpeningHandshakeException (a subclass of WebSocketException) when a violation against the WebSocket protocol is detected during an opening handshake. For example, when a status code other than 101 is returned from a server.

OpeningHandshakeException provides additional methods such as getStatusLine(), getHeaders() and getBody() to access the response from a server.

You can retrieve the redirection URL like the following.

try
{
    // Perform the WebSocket opening handshake.
    ws.connect();
}
catch (OpeningHandshakeException e)
{
    // Get the status code.
    int statusCode = e.getStatusLine().getStatusCode();

    // If the status code is in the range of 300 to 399.
    if (300 <= statusCode && statusCode <= 399)
    {
        // Location header should hold the redirection URL.
        String location = e.getHeaders().get("Location").get(0);
    }
}
catch (WebSocketException e)
{
}

from nv-websocket-client.

AbdulDroid avatar AbdulDroid commented on July 29, 2024

What of the 200 OK code how does one fix that, cos my URL is correct and the server person is saying they implemented a websocket, what can I do?!?

from nv-websocket-client.

mishaxz avatar mishaxz commented on July 29, 2024

hello, I'm really stuck. I have a strange problem. I get a (not 101) moved permanently 301 error when not using my VPN - but using the VPN I don't have these problems. I use OkHTTP but the only discussions related to this error I could find was the neovisionaries github site.

Could anyone tell me what might be going on? What I should google? would using an actual IP addresses instead of text url help?

from nv-websocket-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.