-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChaosWebSocketServer.cs
65 lines (52 loc) · 1.96 KB
/
ChaosWebSocketServer.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using NetCoreServer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using GTA_SA_Chaos_Mod_Discord.Models;
namespace GTA_SA_Chaos_Mod_Discord
{
class ChaosSession : WsSession
{
public ChaosSession(WsServer server) : base(server) { }
public override void OnWsConnected(HttpResponse response)
{
Console.WriteLine($"Chaos WebSocket client connected a new session with Id {Id}");
}
public override void OnWsDisconnected()
{
Console.WriteLine($"Chaos WebSocket session with Id {Id} disconnected!");
}
protected override void OnError(SocketError error)
{
Console.WriteLine($"Chaos WebSocket session caught an error with code {error}");
}
protected override void OnConnected()
{
Console.WriteLine($"Chat TCP session with Id {Id} connected!");
Console.WriteLine($"Current Sessions Count {Server.ConnectedSessions}");
}
protected override void OnDisconnected()
{
Console.WriteLine($"Chat TCP session with Id {Id} and disconnected!");
Console.WriteLine($"Current Sessions Count {Server.ConnectedSessions}");
}
public override void OnWsReceived(byte[] buffer, long offset, long size)
{
string message = Encoding.UTF8.GetString(buffer, (int)offset, (int)size);
Console.WriteLine("Incoming: " + message);
}
}
class ChaosWebSocketServer : WsServer
{
public ChaosWebSocketServer(IPAddress address, int port) : base(address, port) { }
protected override TcpSession CreateSession() { return new ChaosSession(this); }
protected override void OnError(SocketError error)
{
Console.WriteLine($"Chaos WebSocket server caught an error with code {error}");
}
}
}