Dart changing rapidly so I did not find a way to get data stream from HttpResponse to send arbitrary (even binary) data via websocket. Even file IO has no openInput/OutputStream for now. What is concept for working with data streams in dart at this time?
I'd actually like to get kind of abstract data stream object (like System.IO.Stream in C#) to implement serialization interface with it and then apply it to websocket data stream, so I can change serialization format for my network packets with new serializer implementations in future, or create memory stream object (like System.IO.MemoryStream in C#) to get serialized data in memory.
And finally - is it possible to send binary data with websockets at all?
Thanx.
The
HttpRequestindart:ioimplementsStream<List<int>>. To get the data listen on the stream. An example has recently been added to the API doc at http://api.dartlang.org/docs/releases/latest/dart_io/HttpRequest.html. Thehttp_serverpackage at https://pub.dartlang.org/packages/http_server contains a number of utility classes to handle HTTP.WebSocketimplements bothStreamandStreamSink. When listeming on the stream the objects received will be of typeStringorList<int>depending on whether a string message or a binary data message was sent. Likewise you can add objects of typeStringandList<int>to theWebSocketto send messages.The binary data received will be of type
Uint8Listfrom thedart:typed_datalibrary. I will recommend to useUint8Listwhen sending binary data.As
WebSocketuses streams all the features for streams including transformation are available.