客户端js到c#服务器套接字连接

时间:2020-12-21 16:59:07

标签: javascript c# websocket

我们正在尝试使用 WebSockets 将网页连接到服务器 - 请查看是否有任何错误,提前致谢

c#

public static void Main()
        {
            
            
                TcpListener server = new TcpListener(IPAddress.Parse("ws://127.0.0.1"), 9122);

                server.Start();
                Console.WriteLine("Server has started on  192.168.1.102.{0}Waiting for a connection...", Environment.NewLine);

                TcpClient client = server.AcceptTcpClient();

                Console.WriteLine("A client connected.");
            

        }

js

var exampleSocket = new WebSocket("ws://127.0.0.1:9122", "protocolOne");

                    exampleSocket.onopen = function (event) {
                        exampleSocket.send("Here's some text that the server is urgently awaiting!");
                        console.log(`gdsfgdsfg`);
                    }

0 个答案:

没有答案