1

I'm trying to connect to a json_rpc server in Chrome 62 on DDC 1.24.2 using the standard json_rpc_2 pub package. I'm following the Client based example found at: https://github.com/dart-lang/json_rpc_2#client.

The example fails on the analysis phase (1). What appears to be the best fix fails at runtime (2).

var socket = new HtmlWebSocketChannel.connect(address);
// (1) analysis error: The argument type 'HtmlWebSocketChannel' can't be assigned to the parameter type 'StreamChannel<String>'
_client = new json_rpc.Client(socket);
// (2) runtime error: found = "HtmlWebSocketChannel" expected = "StreamChannel<String>", type = class StreamChannel
_client = new json_rpc.Client(socket.cast<String>());

The solution seems like it should be simple, but I'm not seeing \ finding it. Any help is appreciated. Thanks!

UPDATE 12/5/2017

Instead of a runtime error in Chromium (DartVM) we'd get an infinite hang. Watching network traffic I could see, it just never sent anything. I was unable to get any of the example code to run off their repo.

I ran some tests on just the socket / HtmlWebSocketChannel and I got it sending plain text messages back and forth.

So, I just rolled my own json rpc client. That leaves the original problem unsolved, but the library used in the question appears to have other problems in addition to this. That doesn't really invalidate the question, and I'll leave it here just in case.

  • Can you please try ` var client = new json_rpc.Client(socket as StreamChannel);` – Günter Zöchbauer Dec 06 '17 at 07:38
  • I got the same cast error. I also tried it again in Chromium (w/ DartVM) and the library worked, which I hadn't seen yet (pretty sure it didn't yesterday, but maybe in my frustration I skipped it). – Joshua Ferguson Dec 06 '17 at 12:56
  • With "cast error" you mean Analyzer error or runtime error? – Günter Zöchbauer Dec 06 '17 at 13:13
  • Runtime; _From the sources window_: found = "HtmlWebSocketChannel"; expected = "StreamChannel", type = class StreamChannel; _From the console output_: StrongModeCastError {message: "CastError: Casting value of type 'HtmlWebSocketCha…nel' which is incompatible in strong mode", stack: "dart:_runtime/operations.dart 41:41.. – Joshua Ferguson Dec 06 '17 at 14:14
  • I think it's a bug. `HtmlWebSocketChannel` needs to allow to pass a type parameter. – Günter Zöchbauer Dec 06 '17 at 14:18

0 Answers0