none
Websocket To send data and Receive data RRS feed

  • Question

  • Hi,

    I am connecting to the "wss://*********.azurewebsites.net/ws" using System.Net.WebSockets.ClientWebSocket.ConnectAsync("wss://*********.azurewebsites.net/ws", _cancellationToken) and it gets connected. but I need to send data via the same websocket with additional path /app/chat.sendMessage and receive the respose in “/channel/public". How to perform this step? Please help

    Thanks

    Magesh

    Wednesday, January 17, 2018 3:34 PM

All replies

  • Hello Mageshwaran,

    Did you try to use instance method instead of static method? Something are like below.

     static async Task TestAsync()
            {
                CancellationToken _cancellationToken = new CancellationToken();
                ClientWebSocket clientWebSocket = new ClientWebSocket();
                await clientWebSocket.ConnectAsync(new Uri(""), _cancellationToken);
                if (clientWebSocket.State == WebSocketState.Connecting)
                {
                    clientWebSocket.SendAsync(...);
                }
            }

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 18, 2018 5:44 AM
    Moderator
  • Hi Neil,

    My Query is - How to send data to the URI "wss://*********.azurewebsites.net/ws" via WebSocket which different endpoints for Send and Receive?

    Send : /app/chatMessage

    Receive : /channel/public

    While sending data do I need to use the

    URI like this - "wss://*********.azurewebsites.net/ws?app/chatMessage="+data? Please let me know

    Thursday, January 18, 2018 11:06 AM
  • Hello Mageshwaran,

    As far as I know, The http Uri could take the additional info when send "get" request. And I am not ensure if it's suitable for socket communicate. you could ask experience people at socket relating forum for better solution and support.

    If your server side support http communicate, maybe you could execute a HTTP request using sockets as below link.

    https://stackoverflow.com/questions/11862890/c-how-to-execute-a-http-request-using-sockets

    I'm sorry if it doesn't help you.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 22, 2018 11:16 AM
    Moderator