Has anyone experience with Dart Socket Server and Web Sockets?

1,048 views
Skip to first unread message

Entaro Adun

unread,
Mar 13, 2013, 7:53:47 PM3/13/13
to mi...@dartlang.org
Hello,

maybe someone could provide an anwser or some help to a question posted on stackoverflow: http://stackoverflow.com/questions/15317659/tcp-socket-server-that-listens-to-a-port-and-pushes-data-with-web-sockets


I saw there is a new version of dart:io. How do I create a socket server with the new v2 dart:IO that listens to a port for new data and pushes the received data via Web Sockets to its subscribed clients?

I have a java and a c# desktop application (tcpClient) and I would like to send a string (json or xml) to my dart server on a specific port. That string should be replied to my tcpClient and pushed with Web Sockets to all other subscribed clients(browsers).

I have the following, but how do I access the data that has been sent to that specific socket?

....

Greg Lowe

unread,
Mar 13, 2013, 9:03:29 PM3/13/13
to mi...@dartlang.org
Not sure if this answers your question. But I had a look at this earlier today, and got a bit confused from the WebSocket api docs too.


I haven't had a chance to try this yet - but I think it's something like this:

HttpServer.bind().then((server) {
     server.transform(new WebSocketTransformer()).listen((webSocket) => ... );
});

Probably worth filing a bug about the dart.io.WebSocket docs to add a link to the WebSocketTransformer class.


George Moschovitis

unread,
Mar 14, 2013, 1:35:33 AM3/14/13
to mi...@dartlang.org
WebSocket.connect("ws://echo.websocket.org")
    .then((WebSocket webSocket) {
      webSocket.listen((message) {
          /* Handle message. */
        },
        onDone: () {
          /* Handle closed. */
        });
    });

There is also an example included in the wamp pub package:


-g.

Entaro Adun

unread,
Mar 19, 2013, 7:14:51 PM3/19/13
to mi...@dartlang.org
Thx George, i will look into it.

Greg Lowe

unread,
Mar 19, 2013, 11:48:26 PM3/19/13
to mi...@dartlang.org
The question is about creating a server side (dart:io) application that:

* Listens on plain socket.
  i.e. ServerSocket.bind()

* and, has an HttpServer, that listens for web socket connections.
     i.e. HttpServer.bind() and WebSocketTransformer.upgrade()
     See the example on the WebSocketTransformer page linked below.

* sends any data received on the plain socket to all of the currently connected web sockets. 
    i.e. something like: serverSocket.listen((data) { webSockets.forEach((ws) => ws.send(data)) })

* George's example shows how a client can connect to the http server using a web socket.


Reply all
Reply to author
Forward
0 new messages