fixed: added catch error websocket
This commit is contained in:
@@ -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,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;
|
||||
@@ -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<byte>(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);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class WebSocketTaskScheduler: TaskScheduler
|
||||
{
|
||||
TryExecuteTask(task);
|
||||
|
||||
if (task.Status != TaskStatus.RanToCompletion)
|
||||
if (task.Status == TaskStatus.Running)
|
||||
_pendingTasks.Enqueue(task);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user