简体   繁体   English

用一个参数打开一个websocket连接

[英]Open a websocket connection with a parameter

When opening a websocket connection (in JavaScript) to my custom server I wrote (C#), I want to include a parameter at the end of the URL for example 'ws://127.0.0.1:9003/myParameter'.当打开 websocket 连接(在 JavaScript 中)到我编写的自定义服务器(C#)时,我想在 URL 的末尾包含一个参数,例如“ws://127.0.0.1:9003/myParameter”。

        var socket = new WebSocket('ws://127.0.0.1:9003/myParameter');

        socket.onopen = function () {
            deferred.resolve(true);
            socket.close();
        };

On the server side I have this method accepting connections:在服务器端,我有这个方法接受连接:

 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                t.Start();
                while (true)
                {
                    TcpClient c = t.AcceptTcpClient();
                    WebSocketClient w = new WebSocketClient(c);
                    webSocketClientManager.AddClient(w);
                }                   
            }
            catch (Exception ex)
            {
                // log error
            }
        }
    }

I have no issues establishing the connection.建立连接没有问题。 What I would like is to somehow read/see if 'myParameter' exists in the URL as it is trying to connect.我想要以某种方式读取/查看 URL 中是否存在“myParameter”,因为它正在尝试连接。

TIA TIA

ws://127.0.0.1:9003/path?param=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM