sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.74k stars 1.66k forks source link

when handshaking, HttpContext.WebSockets.IsWebSocketRequest always being false #743

Closed SandyLovegood closed 11 months ago

SandyLovegood commented 11 months ago

I tried this in Unity, with a websocket server build with aspnetcore. But when try to perform Connect() or ConnectAsyc(), the server recieve a http request with HttpContext.WebSockets.IsWebSocketRequest being false, thus the socket cannot be established. Has anyone get some clue?

In the server side, controller's code being like:

    [HttpGet("/testWebSocket")]
    public async Task WebSocketServer()
    {
        if (HttpContext.WebSockets.IsWebSocketRequest)//it's always false in here.
        {
            try
            {
                _socket = await HttpContext.WebSockets.AcceptWebSocketAsync();
                await new WebSocketHelper().WebSocketReceive(_socket);
            }
            catch (Exception e) {
        }
        }
    }
SandyLovegood commented 11 months ago

Can it be the issue between http2 and http1?

SandyLovegood commented 11 months ago

my bad. I‘ve found this link and it explains everything. Pls consider this issue to be closed.