From 8a149eb3b49540534c16a262c54dfeb6dde85adc Mon Sep 17 00:00:00 2001 From: Edmand46 Date: Sun, 23 Oct 2022 18:45:37 +0400 Subject: [PATCH] fixed: added catch error websocket --- Ragon.Common/Sources/RagonOperation.cs | 6 ------ Ragon/Sources/Application.cs | 3 +-- Ragon/Sources/Server/Http/WebSocketServer.cs | 16 ++++++++++++---- .../Server/Http/WebSocketTaskScheduler.cs | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Ragon.Common/Sources/RagonOperation.cs b/Ragon.Common/Sources/RagonOperation.cs index 32e9b7a..5273e44 100644 --- a/Ragon.Common/Sources/RagonOperation.cs +++ b/Ragon.Common/Sources/RagonOperation.cs @@ -5,7 +5,6 @@ namespace Ragon.Common AUTHORIZE, AUTHORIZED_SUCCESS, AUTHORIZED_FAILED, - JOIN_OR_CREATE_ROOM, CREATE_ROOM, JOIN_ROOM, @@ -13,19 +12,14 @@ namespace Ragon.Common OWNERSHIP_CHANGED, JOIN_SUCCESS, JOIN_FAILED, - LOAD_SCENE, SCENE_LOADED, - PLAYER_JOINED, PLAYER_LEAVED, - CREATE_ENTITY, DESTROY_ENTITY, SNAPSHOT, - REPLICATE_ENTITY_STATE, REPLICATE_ENTITY_EVENT, - REPLICATE_EVENT, } } \ No newline at end of file diff --git a/Ragon/Sources/Application.cs b/Ragon/Sources/Application.cs index 86ab25e..40c1bf3 100755 --- a/Ragon/Sources/Application.cs +++ b/Ragon/Sources/Application.cs @@ -1,7 +1,6 @@ using System; using System.Threading; using Ragon.Common; -using ENet; using NLog; namespace Ragon.Core @@ -31,7 +30,7 @@ namespace Ragon.Core var dispatcher = new Dispatcher(); _dispatcher = dispatcher; - _socketServer = new WebSocketServer(this); + _socketServer = new ENetServer(this); _deltaTime = 1000.0f / configuration.SendRate; _roomManager = new RoomManager(factory, this); diff --git a/Ragon/Sources/Server/Http/WebSocketServer.cs b/Ragon/Sources/Server/Http/WebSocketServer.cs index ebda88d..33ca38e 100644 --- a/Ragon/Sources/Server/Http/WebSocketServer.cs +++ b/Ragon/Sources/Server/Http/WebSocketServer.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Net; using System.Net.WebSockets; using System.Threading; @@ -19,7 +20,7 @@ public class WebSocketServer : ISocketServer private WebSocketTaskScheduler _webSocketScheduler; private TaskFactory _taskFactory; private HttpListener _httpListener; - + public WebSocketServer(IEventHandler eventHandler) { _eventHandler = eventHandler; @@ -53,9 +54,16 @@ public class WebSocketServer : ISocketServer var buffer = new Memory(bytes); while (webSocket.State == WebSocketState.Open) { - var result = await webSocket.ReceiveAsync(buffer, CancellationToken.None); - var dataRaw = buffer.Slice(0, result.Count); - _eventHandler.OnData(peerId, dataRaw.ToArray()); + try + { + var result = await webSocket.ReceiveAsync(buffer, CancellationToken.None); + var dataRaw = buffer.Slice(0, result.Count); + _eventHandler.OnData(peerId, dataRaw.ToArray()); + } + catch (Exception ex) + { + break; + } } _eventHandler.OnDisconnected(peerId); diff --git a/Ragon/Sources/Server/Http/WebSocketTaskScheduler.cs b/Ragon/Sources/Server/Http/WebSocketTaskScheduler.cs index 67d9708..1f8429d 100644 --- a/Ragon/Sources/Server/Http/WebSocketTaskScheduler.cs +++ b/Ragon/Sources/Server/Http/WebSocketTaskScheduler.cs @@ -41,7 +41,7 @@ public class WebSocketTaskScheduler: TaskScheduler { TryExecuteTask(task); - if (task.Status != TaskStatus.RanToCompletion) + if (task.Status == TaskStatus.Running) _pendingTasks.Enqueue(task); }