fixed: added catch error websocket

This commit is contained in:
2022-10-23 18:45:37 +04:00
parent 14ae5e8189
commit 8a149eb3b4
4 changed files with 14 additions and 13 deletions
-6
View File
@@ -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,
}
}
+1 -2
View File
@@ -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);
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.WebSockets;
using System.Threading;
@@ -52,11 +53,18 @@ public class WebSocketServer : ISocketServer
var bytes = new byte[2048];
var buffer = new Memory<byte>(bytes);
while (webSocket.State == WebSocketState.Open)
{
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);
}
@@ -41,7 +41,7 @@ public class WebSocketTaskScheduler: TaskScheduler
{
TryExecuteTask(task);
if (task.Status != TaskStatus.RanToCompletion)
if (task.Status == TaskStatus.Running)
_pendingTasks.Enqueue(task);
}