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

Unified Diff: runtime/bin/websocket.dart

Issue 10205012: Initial web socket server implementation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/websocket.dart
diff --git a/runtime/bin/websocket.dart b/runtime/bin/websocket.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f0ae90e1d355a53b90d040a24d1cad781cc23938
--- /dev/null
+++ b/runtime/bin/websocket.dart
@@ -0,0 +1,78 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/**
+ * The web socket protocol is implemented by a HTTP server handler
+ * which can be instantiated like this:
+ *
+ * WebSocketHandler wsHandler = new WebSocketHandler();
+ *
+ * and then its onRequest method can be assigned to the HTTP server, e.g.
+ *
+ * server.defaultHandler = wsHandler.onRequest;
+ *
+ * or
+ *
+ * server.addRequestHandler((req) => reg.path == "/ws", wsHandler.onRequest);
+ *
+ */
+interface WebSocketHandler default _WebSocketHandler {
+ WebSocketHandler();
+
+ /**
+ * Request handler to be registered with the HTTP server.
+ */
+ void onRequest(HttpRequest request, HttpResponse response);
+
+ /**
+ * Sets the callback to be called when a new web socket connection
+ * has been established.
+ */
+ void set onConnection(callback(WebSocketConnection connection));
+}
+
+
+/**
+ * Web socket connection.
+ */
+interface WebSocketConnection {
+ /**
+ * Sets the callback to be called when a message have been
+ * received. The type on [message] is either [:String:] or
+ * [:List<int>:] depending on whether it is a text or binary
+ * message. If the message is empty [message] will be [:null:].
+ */
+ void set onMessage(void callback(Object message));
+
+ /**
+ * Sets the callback to be called when the web socket connection is
+ * closed.
+ */
+ void set onClosed(void callback(int status, String reason));
+
+ /**
+ * Sets the callback to be called when the web socket connection
+ * encountered an error.
+ */
+ void set onError(void callback(e));
+
+ /**
+ * Sends a message. The [message] must be a [:String:] a
+ * [:List<int>:] or [:null:].
+ */
+ send(Object message);
+
+ /**
+ * Close the web socket connection. The default value for [status]
+ * and [reason] are [:null:].
+ */
+ close([int status, String reason]);
+}
+
+
+class WebSocketException implements Exception {
+ const WebSocketException([String this.message = ""]);
+ String toString() => "WebSocketException: $message";
+ final String message;
+}

Powered by Google App Engine
This is Rietveld 408576698