Skip to content

Commit

Permalink
preparing WebSocketClient.cs to run as server side mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Nov 15, 2023
1 parent 1906fc8 commit 911e3a3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/WebSocket/WebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ public class WebSocketClient : IWebsocketClient
private EventHandler<Exception> _onError;
private EventHandler _onOpen;
private readonly List<(byte[] buffer, BufferType bufferType)> _bufferList;
private bool _tryConnecting, _tryClosing;
private bool _tryConnecting, _tryClosing, _initServerSide;
private readonly bool _serverSide;
private readonly object _bufferLock;
private ClientWebSocket _websocket;
private WebSocket _ws;


public WebSocketClient()
Expand All @@ -38,10 +40,22 @@ public WebSocketClient()
_serverSide = false;
}

internal WebSocketClient(WebSocket websocket)
{
_serverSide = true;
_ws = websocket;
}

internal void InitWebSocketServerSide()
{
if(_initServerSide) return;
_ReceiveData();
_initServerSide = true;
}

public void Open(Uri uri)
{
if (IsOpened || _tryConnecting || _tryClosing) return;
if (IsOpened || _tryConnecting || _tryClosing || _serverSide) return;

_tryConnecting = true;

Expand Down

0 comments on commit 911e3a3

Please sign in to comment.