Has anyone experience with Dart Socket Server and Web Sockets?

Showing 1-5 of 5 messages
Has anyone experience with Dart Socket Server and Web Sockets? Entaro Adun 3/13/13 4:53 PM
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?

....

Re: Has anyone experience with Dart Socket Server and Web Sockets? Greg Lowe 3/13/13 6:03 PM
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.


Re: Has anyone experience with Dart Socket Server and Web Sockets? George Moschovitis 3/13/13 10:35 PM
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.
Re: Has anyone experience with Dart Socket Server and Web Sockets? Entaro Adun 3/19/13 4:14 PM
Thx George, i will look into it.
Re: Has anyone experience with Dart Socket Server and Web Sockets? Greg Lowe 3/19/13 8:48 PM
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.