tiger154 / jwebsocket

Automatically exported from code.google.com/p/jwebsocket
1 stars 0 forks source link

No trailing \r\n in handshake headers. Prevents some servers from answering to handshake request. #168

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm trying to build android application that uses websockets. When I open 
websocket connection to my local WS server (based on pythons autobahn-0.4.2), 
the call to open() will block indefinitely.

The problem is that jwebsocket generates non HTTP compliant headers for the 
handshake: \r\n\r\n is missing after last header.

On android side, I am opening WS client this way:

        BaseTokenClient client = new BaseTokenClient();
        try {
            client.open(url);
        } catch (WebSocketException e) {
            e.printStackTrace();
        }

A am using jwebsocket compiled from 
http://jwebsocket.googlecode.com/svn/branches/jWebSocket-1.0 rev 1842. (Latest 
rev 1844 won't compile). 

Patch below fixes the problem:

Index: shared/J2SE/jWebSocketCommon/org/jwebsocket/kit/WebSocketHandshake.java
===================================================================
--- 
shared/J2SE/jWebSocketCommon/org/jwebsocket/kit/WebSocketHandshake.java (revisio
n 1842)
+++ 
shared/J2SE/jWebSocketCommon/org/jwebsocket/kit/WebSocketHandshake.java (working
 copy)
@@ -552,6 +552,7 @@
            if (mVersion != null) {
                lHandshake += "Sec-WebSocket-Version: " + mVersion + "\r\n";
            }
+           lHandshake += "\r\n";
            try {
                lHandshakeBytes = lHandshake.getBytes("UTF-8");
            } catch (UnsupportedEncodingException ex) {

Original issue reported on code.google.com by andrey.l...@gmail.com on 20 Mar 2012 at 4:05