How to set Websocket-sharp connection between WPF app and ASP.Net app?

2.1k views Asked by At

I have a desktop application (WPF) and a web application (ASP.Net) and want to set connection using WebSocket-Sharp.

On client side:

        using (var ws = new WebSocket("ws://localhost:8085"))
        {
            var data = new byte[] { 1, 2, 3, 4, 5 };
            ws.OnMessage += (send, args) =>
            {
                Status = "WebSocket. OnMessageEvent!";
            };

            ws.Connect();

            if (ws.IsAlive)
            {
                ws.Send(data);
            }

            ws.Close();
        }

On server side:

        var wssv = new WebSocketSharp.Server.WebSocketServer("ws://localhost:8085");

        wssv.Start();

        wssv.AddWebSocketService<Chat>("/Chat");

Chat is a class that inherites WebSocketBehavior class.

There are two questions:

  1. How to identify right place to put code on server side?

  2. Should a port that I set in IIS to be different from WebSocket? May I set any port to WebSocket?

Thank you!

0

There are 0 answers