-
Notifications
You must be signed in to change notification settings - Fork 2
/
IConnectionManager.cs
28 lines (26 loc) · 1.2 KB
/
IConnectionManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//-------------------
// Reachable Games
// Copyright 2023
//-------------------
using System.Threading.Tasks;
using System.Net;
namespace ReachableGames
{
namespace RGWebSocket
{
// IConnectionManager allows you to implement a class that manages a bunch of websocket connections.
// Each of the callbacks can be async or not. If not, just return Task.CompletedTask.
// The rationale for a single object that manages many connections is, generally you will have to look up
// the state of a connection and do something with the messages that you service, and there's a certain amount
// of central bookkeeping that must exist for that, plus the message dictionaries are usually the same for all
// connections, so it reduces overhead to put them in one place. This neatly gives you a place to implement that.
public interface IConnectionManager
{
Task OnConnection(RGWebSocket rgws, HttpListenerContext context);
Task OnDisconnect(RGWebSocket rgws);
Task OnReceiveText(RGWebSocket rgws, string msg);
Task OnReceiveBinary(RGWebSocket rgws, PooledArray msg);
Task Shutdown(); // When shutting down, IConnectionManager must iterate over all RGWebSockets and call .Close() on them.
}
}
}