Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Issue 10205012: Initial web socket server implementation (Closed)

Created:
8 years, 8 months ago by Søren Gjesse
Modified:
8 years, 8 months ago
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Initial web socket server implementation This implements the web socket protocol as a request handler for the HTTP server. The HTTP server have been updated with the ability of getting the socket when a HTTP upgrade request is processed. This way the web socket implementation is not builtin to the HTTP server. The API on the server is: interface WebSocketConnection { void set onMessage(void callback(Object message)); void set onClosed(void callback(int status, String reason)); void set onError(void callback(e)); send(Object message); close([int status, String reason]); } This API currently does not have any streaming but collects the entire message before invoking the onMessage callback. The current browser web socket API (http://dev.w3.org/html5/websockets/) works the same way. The underlying web socket protocol can have unbounded messages so long term this probably have to change. But for now the only likely client for a web socket server is a browser. Currently this is missing tests. The implementation has been tested by running the WebSocketTest.dart script and connecting using a browser. This testing have been done using Chrome 19 and Firefox 11. I will be adding tests in separate change lists. The SHA-1 and base 64 code (initially written by ajohnsen@google.com) can be removed when these algorithms is available in the dart:crypto. R=ager@google.com, ajohnsen@google.com, vsm@google.com, jacobr@google.com BUG=dart:2001 TEST=none Committed: https://code.google.com/p/dart/source/detail?r=6998

Patch Set 1 #

Total comments: 28

Patch Set 2 : Addressed review comments from ajohnsen@ and ager@ #

Total comments: 6

Patch Set 3 : Addressed review comments from vsm@ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1086 lines, -14 lines) Patch
A runtime/bin/base64.dart View 1 1 chunk +104 lines, -0 lines 0 comments Download
M runtime/bin/http.dart View 1 1 chunk +10 lines, -0 lines 0 comments Download
M runtime/bin/http_impl.dart View 1 11 chunks +49 lines, -10 lines 0 comments Download
M runtime/bin/http_parser.dart View 1 4 chunks +14 lines, -4 lines 0 comments Download
M runtime/bin/io_sources.gypi View 3 chunks +4 lines, -0 lines 0 comments Download
A runtime/bin/sha1.dart View 1 chunk +104 lines, -0 lines 0 comments Download
A runtime/bin/websocket.dart View 1 2 1 chunk +78 lines, -0 lines 0 comments Download
A runtime/bin/websocket_impl.dart View 1 2 1 chunk +594 lines, -0 lines 0 comments Download
A tests/standalone/src/crypto/Base64Test.dart View 1 chunk +69 lines, -0 lines 0 comments Download
A tests/standalone/src/crypto/Sha1Test.dart View 1 chunk +60 lines, -0 lines 0 comments Download

Messages

Total messages: 9 (0 generated)
Søren Gjesse
8 years, 8 months ago (2012-04-24 11:55:24 UTC) #1
Anders Johnsen
First drive-by comments. https://chromiumcodereview.appspot.com/10205012/diff/1/runtime/bin/http.dart File runtime/bin/http.dart (right): https://chromiumcodereview.appspot.com/10205012/diff/1/runtime/bin/http.dart#newcode393 runtime/bin/http.dart:393: Socket protocolUpgrade(); Further comment that this ...
8 years, 8 months ago (2012-04-24 12:20:47 UTC) #2
Mads Ager (google)
https://chromiumcodereview.appspot.com/10205012/diff/1/runtime/bin/base64.dart File runtime/bin/base64.dart (right): https://chromiumcodereview.appspot.com/10205012/diff/1/runtime/bin/base64.dart#newcode17 runtime/bin/base64.dart:17: // Endianness matters? Did you resolve this? If not ...
8 years, 8 months ago (2012-04-25 10:41:54 UTC) #3
Søren Gjesse
https://chromiumcodereview.appspot.com/10205012/diff/1/runtime/bin/base64.dart File runtime/bin/base64.dart (right): https://chromiumcodereview.appspot.com/10205012/diff/1/runtime/bin/base64.dart#newcode17 runtime/bin/base64.dart:17: // Endianness matters? On 2012/04/25 10:41:55, Mads Ager wrote: ...
8 years, 8 months ago (2012-04-25 13:57:14 UTC) #4
Mads Ager (google)
lgtm
8 years, 8 months ago (2012-04-25 14:26:05 UTC) #5
vsm
https://chromiumcodereview.appspot.com/10205012/diff/8001/runtime/bin/websocket.dart File runtime/bin/websocket.dart (right): https://chromiumcodereview.appspot.com/10205012/diff/8001/runtime/bin/websocket.dart#newcode46 runtime/bin/websocket.dart:46: void set onMessage(void callback(Object message)); Consider making this consistent ...
8 years, 8 months ago (2012-04-25 16:45:18 UTC) #6
Sean Eagan
Great stuff! I had a couple ideas to improve WebSocketConnection if you don't mind me ...
8 years, 8 months ago (2012-04-25 18:14:35 UTC) #7
Søren Gjesse
Thanks for the review seaneagan1: Thanks for the comments. For this API we are currently ...
8 years, 8 months ago (2012-04-26 09:37:44 UTC) #8
Sean Eagan
8 years, 8 months ago (2012-04-26 13:14:09 UTC) #9
On 2012/04/26 09:37:44, Søren Gjesse wrote:
> seaneagan1:
> Thanks for the comments. For this API we are currently trying to have some
> consistency with the w3c client API from http://dev.w3.org/html5/websockets/.

I think just developing the best API possible, and then, if necessary, changing
the client API in dart:html to be consistent (similar to
http://dartbug.com/2677) would be welcome.

> However as you state the most common case will be to handle only text or only
> binary messages on a given handler. I would like to address this through
adding
> a property on the WebSocketHandler. You can set whether to expect test or
binary
> messages, and if an unexpected type is received the WebSocketHandler will just
> close the web socket with an error. You can then rely on the message passed to
> onMessage will always be of the expected type. I will address that as a
separate
> change and I hope it will work for you.

Sounds good, a small tweak, rather than a property to designate text vs. binary,
how about a type parameter:

interface WebSocketHandler<T> {
  //...
  void set onOpen(callback(WebSocketConnection<T> connection));
}

interface WebSocketConnection<T> {
  void set onMessage(void callback(T message));
  send T message);
}

and then add sub-interfaces whose implementation constrain the messages to only
text (String) or only binary (List<int>):

interface WebSocketTextHandler extends WebSocketHandler<String> //...
interface WebSocketBinaryHandler extends WebSocketHandler<List<int>> //...

Powered by Google App Engine
This is Rietveld 408576698