Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

MVC4, WebSocket, Safari context.IsWebSocketRequest is false

I am using Windows 8 with IIS8 and MVC4 to establish a websocketconnection. This works fine with Firefox, IE10 and Chrome. Safari still wont let me establish a websocketconnection. My Handlercode looks like this:

<!-- language: c# -->
public void ProcessRequest(HttpContext context)
{
if (context.IsWebSocketRequest)
{
Client client = new Client();
context.AcceptWebSocketRequest(client.HoldConnection);
}
}

The Problem is that context.IsWebSocketRequest is always false, while conntecting via Safari. My JavaScript code is a simple this.socket = new WebSocket(window.WebSocketUrl);

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are two incompatible versions of the websocket protocol in use. Safari uses the original (now deprecated) Hixie variant; Firefox, IE10 and Chrome use the newer Hybi variant

Its quite possible to build a websocket server that speaks both versions but it sounds like MVC4 only supports Hybi clients.

Safari will eventually catch up. If you can't wait for this you could consider either using an alternative server which supports both websocket variants or rework your clients to poll instead (either as standard or as a fall-back when websocket connection fails).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...