wjohnson
wjohnson

Reputation: 761

Can one implement a Dart command line WebSocket client that supports two-way exchanges with a server?

I'm trying to create command line Dart apps that have two goals:

It appears that importing dart:html in a source file triggers expectations in both IJ and DE that an HTML page is the entry point into the Dart main(). Also (in IJ), the Select/Run/Debug items in the context menu are not added for Dart source files that import dart:html but are for my unittest source files without this import statement. This complicates the workflow by requiring that my Dartium browser become involved. I have successfully created a simple echo WS script using the recipe shown in the section A Command Line WebSocket Client, but this example only listens for but does not send messages. In fact, the API of the io:WebSocket has no 'send' method as does its html:WebSocket counterpart. The io:WebSocket appears to be much weaker than its 'html' counterpart. So for my use cases (or for someone trying to write a middle-tier Dart-based server), can this be done and how?

Upvotes: 2

Views: 477

Answers (2)

montyr75
montyr75

Reputation: 941

I do pretty extensive work with server-side WebSocket programming in Dart, and it seems quite full-featured to me. Lately, I've been using the Redstone framework with the WebSocket plugin, which removes much of the boilerplate and makes it almost too easy...

Upvotes: 3

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657308

You can. As far as I remember in dart:io it is just add instead of send. I didn't have the impression that the io:WebSocket has less capabilities.

See https://api.dartlang.org/apidocs/channels/be/dartdoc-viewer/dart:io.WebSocket#id_add
You have to click the add link below Methods (deep links don't work properly yet in api.dartlang.org).

Upvotes: 2

Related Questions