当前位置: 动力学知识库 > 问答 > 编程问答 >

websocket - Does web sockets only support 1 connection using IIS 8 Client

问题描述:

i have a MVC asp.net web app.

It is hosted on my local network on a Windows 8.1 32bit OS.

I have found that SignalR only supports 1 client connection.

So, I removed SignalR and switched to web sockets.

However, this did not solve the problem.

Am I accurate in stating that Web Sockets only supports 1 client connection on this OS and IIS 8 Client?

Is the solution to use IIS Express because I had problems getting this to work and in the end ended up rebuilding my PC.

Is there no workaround for this issue?

This is my code:

In my Global.cs file:

public static WebSocketCollection clients = new WebSocketCollection();

In my handler:

public class MicrosoftWebSockets : WebSocketHandler

{

private string name;

public override void OnOpen()

{

this.name = this.WebSocketContext.QueryString["chatName"];

MvcApplication.clients.Add(this);

//clients.Broadcast(name + " has connected.");

}

public void SendImage(byte[] jpeg)

{

this.Send(jpeg);

}

public override void OnMessage(string message)

{

MvcApplication.clients.Broadcast(string.Format("{0} said: {1}", name, message));

}

public override void OnClose()

{

MvcApplication.clients.Remove(this);

MvcApplication.clients.Broadcast(string.Format("{0} has gone away.", name));

}

}

In my HTML page:

 var conversation = $('conversation');

var url = 'ws://192.168.0.13:80/SocketHandler.ashx?name=John Doe';

ws = new WebSocket(url);

ws.binaryType = 'arraybuffer';

ws.onerror = function (e) {

$('#divSystemMessage').html('Problem with connection: ' + e.message);

};

ws.onopen = function () {

$('#divSystemMessage').html('Client connected');

};

ws.onmessage = function (e) {

liveViewIndex = 0;

desktopImage.src = 'data:image/jpeg;base64,' + base64ArrayBuffer(e.data);

};

ws.onclose = function () {

$('#divSystemMessage').html('Closed connection!');

};

public class SocketHandler : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

if (context.IsWebSocketRequest)

context.AcceptWebSocketRequest(new MicrosoftWebSockets());

}

public bool IsReusable

{

get

{

return false;

}

}

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: