Getting status code 404 while making websocket connection

Issue #17 closed
Sachin D Agrawal created an issue

Getting status code 404 while making websocket connection

I was trying to make a websocket using your sample to a websocket running on a server as a java process in the format ws://<server name>:6500

Example : ws://abc.svr.abc:6500 where abc.svr.abc is the server name

However, I am getting a 404 error, as seen in attached screenshot.

Requesting you to please look into this and advice. Thanks & Regards, Sachin

Comments (32)

  1. Peter Doornbosch repo owner

    That is http status code 404: not found. So you're using a URL that the web server does not serve. Probably, you need to append some path, e.g. ws://abc.svr.abc:6500/here_it_is, but obviously, i cannot tell you which URL you should use. There is no magic going on: a websocket connection by definition starts with a http request (the "upgrade" request), which is simply a GET request with some special headers. All normal http rules apply: if the request URI does not exists you get a 404, if you're no authorized, you'll get a 401, etc.

    Hope this helps.

  2. Sachin D Agrawal reporter

    Peter, Thanks a lot for your response. Now, even if I am trying echo.websocket.org example for websockets, it is giving a timeout error. Does it suggests that something is wrong, as this should have worked?

    Also, for the previous example, we are making a websocket connection to a java process running on a unix server and not directly to any http web server. Can you please explain bit more how do we handle this case using your plugin.

    Thanks & Regards, Sachin

  3. Peter Doornbosch repo owner

    Hi Sachin,

    Yes, the echo.websocket.org sample should work. Sometimes it doesn't, their site may be down or being updated, it's not under my control ;-). I just tried it and it works fine now. Please try again?

    It doesn't matter that you are not connecting to a http web server. Any websocket server will support the http upgrade request, it is the only way to start a websocket connection! See for example http://blog.teamtreehouse.com/an-introduction-to-websockets (scroll down to "How WebSockets Work") or https://tools.ietf.org/html/rfc6455.

    Cheers, Peter

  4. Sachin D Agrawal reporter

    Hi Peter,

    Thanks for your response again. I tried echo.websocket.org again and it is still giving connection time out. Can you please advice if I need to perform any configurations/settings to use your plugin, some proxy setting, etc as it is still not working from my office machine. Also, Can you please advice of a simple way to test websocket connection using any readily available websockets other than echo.websocket.org, just to prove the setup and plugin is working fine on my machine.

    Thanks again for your help and co-operation. Please let me know about the same. Thanks & Regards, Sachin

  5. Peter Doornbosch repo owner

    Hi Sachin,

    • can you telnet echo.websocket.org 80 (does it say "Connected to echo.websocket.org" or "Operation timed out" / "Unable to connect to remote host"?)
    • if you can't, it is obvious JMeter can't either. If you are behind a proxy, you can't use plugin, because version 0.7.x does not support http proxy (you could try the "proxy" branch though)
    • if you can, and the sample test plan still results in a timeout, than something very strange is going on. Please check that you didn't accidentally modify the test plan.

    To test the websocket connection, you would need a (simple) web socket server. Assuming you are a Java developer, you can build one yourself. See for example this blog https://blog.idrsolutions.com/2013/12/websockets-an-introduction/ (you don't have to create html client, once the java server is running you can test it with JMeter) or this https://blog.openshift.com/how-to-build-java-websocket-applications-using-the-jsr-356-api/.

    The last one is maybe the fastest, as it is a working example: download the code from https://github.com/shekhargulati/wordgame, build it, run it (you need an awful lot of libraries on the classpath, see below), take my wordgame.jmx from the samples dir, run it and be happy! ;-)

    Run command for the wordgame server (replace "/Users/peter" with your home dir):

    java -cp target/wordgame-0.0.1-SNAPSHOT.jar:/Users/peter/.m2/repository/org/glassfish/tyrus/tyrus-server/1.1/tyrus-server-1.1.jar:/Users/peter/.m2/repository/javax/websocket/javax.websocket-api/1.0/javax.websocket-api-1.0.jar:/Users/peter/.m2/repository/org/glassfish/tyrus/tyrus-container-grizzly/1.1/tyrus-container-grizzly-1.1.jar:/Users/peter/.m2/repository/org/glassfish/tyrus/tyrus-spi/1.1/tyrus-spi-1.1.jar:/Users/peter/.m2/repository/org/glassfish/grizzly/grizzly-http-server/2.3.3/grizzly-http-server-2.3.3.jar:/Users/peter/.m2/repository/org/glassfish/tyrus/tyrus-core/1.1/tyrus-core-1.1.jar:/Users/peter/.m2/repository/org/glassfish/tyrus/tyrus-websocket-core/1.1/tyrus-websocket-core-1.1.jar:/Users/peter/.m2/repository/org/glassfish/grizzly/grizzly-http-servlet/2.2.16/grizzly-http-servlet-2.2.16.jar:/Users/peter/.m2/repository/org/glassfish/grizzly/grizzly-http/2.3.3/grizzly-http-2.3.3.jar:/Users/peter/.m2/repository/org/glassfish/grizzly/grizzly-framework/2.3.3/grizzly-framework-2.3.3.jar: com.shekhar.wordgame.server.WebSocketServer

  6. Sachin D Agrawal reporter

    Hi Peter,

    I did some further investigation using another jmeter plugin for websocket by maciejzaleski and I was not getting connection timeout for both "echo.websocket.org" as well as the websocket server which I tried earlier. Attaching screenshots using maciejzaleski plugin as well as results data. Thus, seems someway issue I was facing earlier in the Problem statement is specific to your plug-in. Also, does your plugin automatically adds "/" at the end of the url, be default. Is this fine? Can you please investigate more about the original and let us know.

    Thanks & Regards, Sachin

  7. Peter Doornbosch repo owner

    Hi Sachin,

    Thanks for the update. And yes, i really like to find out why the plugin is not working.

    My first guess is that it is related to using a proxy server. Can you confirm that you are / are not using a proxy? If you don't know, how do you start JMeter? Are you passing command line args like "-H" or "-P?

    Can you add a screenshot showing how the "WebSocket Open Connection" sampler is configured? And which version of the plugin are you using?

  8. Sachin D Agrawal reporter

    Hi Peter,

    Thanks for replying.

    1) I am starting jmeter as cmd, cd ../<jmeterhome>/bin folder and then typing "jmeter". I am not passing any command ling args.

    2) Attaching screenshot of websocket open connection sample which I am using.

    3) The version of plugin I am using is : JMeterWebSocketSamplers-0.7.3.jar

    Please let me know if any other information is required. Thanks & Regards, Sachin

  9. Peter Doornbosch repo owner

    You are running Windows, i guess? Can you try setting up a telnet connection to echo.websocket.org port 80? Does it succeed in creating the connection, or do you get a connection refused?

  10. Sachin D Agrawal reporter

    Hi Peter,

    For echo.websocket.org, port 80, while doing telnet not able to connect but using our websocket and port, we were able to successfully connect using telnet.

    And, For our websocket and port, using your plugin getting errors as below :-

    From Results Tree WebSocket error: java.net.UnknownHostException: <server name>

    From Jmeter console 017/04/20 08:08:57 ERROR - eu.luminis.jmeter.wssampler.OpenWebSocketSampler: I/O Error in sampler 'WebSocket Open Connection'. java.net.UnknownHostException: <server name> at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at eu.luminis.websocket.WebSocketClient.createSocket(WebSocketClient.java:166) at eu.luminis.websocket.WebSocketClient.connect(WebSocketClient.java:108) at eu.luminis.websocket.WebSocketClient.connect(WebSocketClient.java:81) at eu.luminis.jmeter.wssampler.WebsocketSampler.sample(WebsocketSampler.java:106) at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:475) at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:418) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:249) at java.lang.Thread.run(Thread.java:745)

    And, using the other maciejzaleski plugin, we are able to connect successfully to both echo.websocket.org and our websocket & port.

    Please let me know if any other information is required. Thanks & Regards, Sachin

  11. Sachin D Agrawal reporter

    Also, attaching modified snippet (specific details removed) from recording of loadrunner if this helps.

    Action() {

    web_set_sockets_option("SSL_VERSION", "TLS1.1");
    
    
        web_websocket_connect("ID=0", 
        "URI=ws:<server name>", 
        "Origin=file://", 
        "OnOpenCB=OnOpenCB0", 
        "OnMessageCB=OnMessageCB0", 
        "OnErrorCB=OnErrorCB0", 
        "OnCloseCB=OnCloseCB0", 
        LAST);
    
    web_websocket_send("ID=0", 
        "Buffer={\"b\":{\"s\":1,\"c\":1,\"t\":1,\"f\":0} ...}", 
        "IsBinary=0", 
        LAST);
    
    /*Connection ID 0 received buffer WebSocketReceive0*/
    
    web_websocket_send("ID=0", 
        "Buffer={\"b\":{\" ...}", 
        "IsBinary=0", 
        LAST);
    
    /*Connection ID 0 received buffer WebSocketReceive1*/
    
    web_websocket_send("ID=0", 
        "Buffer=0219{\"b\":{\"s\":3, ...}]}}", 
        "IsBinary=0", 
        LAST);
    
    /*Connection ID 0 received buffer WebSocketReceive2*/
    
    web_websocket_send("ID=0", 
        "Buffer=", 
        "IsBinary=0", 
        LAST);
    
    /*Connection ID 0 received buffer WebSocketReceive3*/
    
    web_websocket_send("ID=0", 
        "Buffer=", 
        "IsBinary=0", 
        LAST);
    
    /*Connection ID 0 received buffer WebSocketReceive4*/
    
    web_websocket_send("ID=0", 
        "Buffer=", 
        "IsBinary=0", 
        LAST);
    
    /*Connection ID 0 received buffer WebSocketReceive5*/
    
    web_websocket_send("ID=0", 
        "Buffer=", 
        "IsBinary=0", 
        LAST);
    

    Please let me know if there are any queries. Thanks & Regards, Sachin

  12. Peter Doornbosch repo owner

    Hi Sachin,

    "while doing telnet not able to connect" Well, than it's obvious that the plugin cannot connect either. It must be a proxy thing. Maybe a proxy is configured in jmeter.properties? Or some default Java properties are set that configure a proxy.

    As for the other server, java.net.UnknownHostException indicates that the hostname cannot be resolved. Try to use the IP.

  13. Sachin D Agrawal reporter

    For server thing, I tried using the IP address now but it is showing an error as below

    Results Tree console Http Upgrade failed with status code 404

    JMeter Console 2017/04/20 13:14:44 DEBUG - jmeter.control.GenericController: Calling next on: org.apache.jmeter.control.LoopController 2017/04/20 13:14:45 ERROR - eu.luminis.jmeter.wssampler.OpenWebSocketSampler: Http upgrade error in sampler 'WebSocket Open Connection'. eu.luminis.websocket.HttpUpgradeException: Http Upgrade failed with status code 404 at eu.luminis.websocket.WebSocketClient.checkHttpStatus(WebSocketClient.java:342) at eu.luminis.websocket.WebSocketClient.checkServerResponse(WebSocketClient.java:294) at eu.luminis.websocket.WebSocketClient.connect(WebSocketClient.java:141) at eu.luminis.websocket.WebSocketClient.connect(WebSocketClient.java:81) at eu.luminis.jmeter.wssampler.WebsocketSampler.sample(WebsocketSampler.java:106) at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:475) at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:418) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:249) at java.lang.Thread.run(Thread.java:745)

  14. Peter Doornbosch repo owner

    And now we are back where we started.... As mentioned in my first comment, 404 means not found. So you're using a URL that the web server does not serve. If you are sure the URL is right, you should check the server logs to find out why it sends a 404.

  15. Sachin D Agrawal reporter

    Hi Peter,

    As we mentioned previously, we are able to telnet for the server as well as make a connection for the same server using the other websocket plugin by maciejzaleski. Thereby, it seems something needs to be investigated from your plugin side.

    Can you please help to investigate this. Thanks & Regards, Sachin

  16. Peter Doornbosch repo owner

    Hi Sachin,

    I would like to help you, but how can i help you? I cannot acces your server, i cannot analyse the log files of your server, i cannot eavesdrop the communication between your client and server, i cannot remotely debug the plugin, these are things you must do yourself.

    For some reason, your server is refusing the connection with a 404. I don't know why and i can't know why, i did not write your server. That's why i suggest you check your servers log files or increase the log level of your server and check the logs.

    As you mention that the other websocket plugin succeeds in setting up the connection, it is probably related to http headers that are different. Again, i cannot see from here which headers are sent when you set up a connection with the other websocket plugin. I could add some debugging to show which headers my plugin is sending in your testplan, but as we need to know the difference, you would still have to find out which headers the other plugin is sending.

    So, you need to collect more information before i can help you. And there are two options: 1) either you find out why your server is refusing the connection (check logging) 2) or we need to find the difference between what the plugins do. There, either (2a) you would need to capture the network traffic between JMeter and server in the two cases, e.g. with a tool like WireShark (check the HTTP upgrade request that starts the websocket connection), or (2b) you try to debug both plugins and set breakpoints so that you can see what headers the plugins are sending.

    (1) and (2a) are pretty easy to do i think. (2b) would be quite do-able for my plugin (set a breakpoint at method setAdditionalUpgradeRequestHeaders() in WebSocketClient). I could create a new version of the plugin that displays the headers in debugging logging, but you still need to collect the headers from the other plugin yourself.

    Regards, Peter

  17. Sachin D Agrawal reporter

    Thanks a lot Peter for letting me know. I will try out the version 0.8 this week and let you know the results.

    Regards, Sachin

  18. Peter Doornbosch repo owner

    Sachin, to enable debug logging you need to add the following to jmeter.properties log_level.eu.luminis.jmeter=DEBUG log_level.eu.luminis.websocket=DEBUG

  19. Log in to comment