flutterdartwebsocketws

receive message from server WebSocketChannel


I am trying to receive a response from a websocket server but only the response that I sent to the server is added and not the one that should be returned to me.

Here I give an example, the following code is just a test, it is not the complete code

final wsUrl = Uri.parse('wss://sip.iptel.org:8081/ws');
final channel = WebSocketChannel.connect(wsUrl);

await channel.ready;

channel.stream.listen((message) {
  channel.sink.add('received!');
});

I tested this code by doing it with the websocket wss://echo.websocket.events and it does add a response and receipt from the server but instead with the address wss://sip.iptel.org:8081/ws I do not receive anything now I will give the examples of what I comes out on each side

enter image description here This is what I receive with the address wss://sip.iptel.org:8081/ws and with the address wss://echo.websocket.events I receive this from here enter image description here


Solution

  • I already solved the problem, if someone has the same problem I will add it here, I just had to add the SIP in the protocols

    var protocol = ['sip']; 
    var webSocketChannel = WebSocketChannel.connect(uri, protocols: protocol); –