I am trying to establish a connection between a web browser client and an ASP.NET server using WebSockets.
I make a set of queries of different sizes and with a few seconds elapsed time between each of them. The first three are transmitted correctly, but the exact one, nothing in particular from the other, closes the WebSocket connection, throws an exception on the server side.
The error message and stack trace of this exception are as follows:
FATAL ERROR: Unable to access the located object.
Object Name: "System.Web.WebSockets.AspNetWebSocket".
in System.Web.WebSockets.AspNetWebSocket.ThrowIfDisposed ()
in System.Web.WebSockets.AspNetWebSocket.SendAsyncImpl (ArraySegment 1 buffer, WebSocketMessageType messageType, Boolean endOfMessage, CancellationToken cancelationToken, Boolean performValidation)
in System.Web.WebSockets.AspNetWebSocket.SendAsync (ArraySegment 1 buffer, WebSocketMessageType messageType, Boolean endOfMessage, CancellationToken cancelationToken)
to [my code path is here ...]
This could be a threading issue because I use async methods everywhere from the functions that communicate with websites.
I know that an exception is thrown from this code (in socket.SendAsync ):
public class SocketTranslater { private WebSocket socket; private JavaScriptSerializer serializer;
A socket is created from another class:
public class EventSender : IHttpHandler { private static List<SocketTranslater> socketTranslaters = new List<SocketTranslater>(); public void ProcessRequest(HttpContext context) { this.id = context.Request.UserHostName + ":" + context.Request.UserAgent; if (context.IsWebSocketRequest) { context.AcceptWebSocketRequest(ProcessSocket); } } private async Task ManageSocket(AspNetWebSocketContext context) { WebSocket socket = context.WebSocket; SocketTranslater translater = new SocketTranslater(socket); translaters.add(translater); while (true) {
Not good, my project is too big to fit all the code here.
Any idea of ββthe source of the error or additional information that you will need?
UPDATE:
After some additional tests, from time to time I don't have this exception. I always do the same, but the server seems random.
This makes my problem even weirder ...