Websockets in cmd line app

594 views
Skip to first unread message

Pete Marshall

unread,
Oct 18, 2012, 8:35:09 AM10/18/12
to mi...@dartlang.org
Hi,
  I'm looking at some Web Socket code.  The browser based example (thanks Seth)  works fine but when I transfer it across to a command line app (using dart:io) I get an error :  Socket closed HttpParserException: Connection closed before full header was received.
Note I'm not seeing the socket open output.
Is it expected that dart:io based websockets should be working? I'm on editor build 13393 and SDK 13387.

Thanks
Pete

initWebSocket() {
     socket = new WebSocket("ws://echo.websocket.org")
     ..onopen = () {;
       print("Socket open");
       connected = true;
       print(socket.readyState);
       socket.send("Hello from Dart");
     }
     ..onclose = (e) {
       print("Socket closed ${(e as CloseEvent).reason}");
       connected = false;
     }
     ..onerror = (e) {
       print("Socket error ${e}");
       connected = false;
     }
     ..onmessage  = (e) {
       print((e as MessageEvent).toString());
     };
   }

Vadim Tsushko

unread,
Oct 18, 2012, 8:56:58 AM10/18/12
to mi...@dartlang.org
Hi, Pete

I have not much to say about this concrete error - but I use WebSocket server and clients, both browser based and console based in Objectory. So you may have a look at it for (hopefully) working example.
I've found debugging of WebSocket intercommunication not so easy yet. As I recollect on some step I saw exactly your error message, but cannot remember now what a situation it was and how I managed to work in out.
 
Best regards, Vadim Tsushko

Søren Gjesse

unread,
Oct 23, 2012, 4:29:11 AM10/23/12
to General Dart Discussion

The problem is that when no path is specified in the URL then the path of the GET request wrongly becomes the empty string.

If you change:

  socket = new WebSocket("ws://echo.websocket.org")

to

  socket = new WebSocket("ws://echo.websocket.org/")

(adding the path /) the web socket connection is established.


Regards,
Søren

--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
 
 

Pete Marshall

unread,
Oct 23, 2012, 5:27:34 AM10/23/12
to mi...@dartlang.org
Thanks for spotting this, I just couldn't see what was wrong, I moved to a different bit of code and parked this one.
Pete

Søren Gjesse

unread,
Oct 23, 2012, 5:40:46 AM10/23/12
to General Dart Discussion
The bug is fixed in https://code.google.com/p/dart/source/detail?r=13939.

Regards,
Søren
Reply all
Reply to author
Forward
0 new messages