-
Notifications
You must be signed in to change notification settings - Fork 2
/
CrowdResponse.cs
44 lines (39 loc) · 1.12 KB
/
CrowdResponse.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
using System;
using System.Net.Sockets;
using System.Text;
using Newtonsoft.Json;
namespace ControlValley
{
public class CrowdResponse
{
public enum Status
{
STATUS_SUCCESS,
STATUS_FAILURE,
STATUS_UNAVAIL,
STATUS_RETRY,
STATUS_KEEPALIVE=255
}
public int id;
public string message;
public int status;
public CrowdResponse(int id, Status status = Status.STATUS_SUCCESS, string message = "")
{
this.id = id;
this.message = message;
this.status = (int)status;
}
public static void KeepAlive(Socket socket)
{
new CrowdResponse(0, Status.STATUS_KEEPALIVE).Send(socket);
}
public void Send(Socket socket)
{
byte[] tmpData = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(this));
byte[] outData = new byte[tmpData.Length + 1];
Buffer.BlockCopy(tmpData, 0, outData, 0, tmpData.Length);
outData[tmpData.Length] = 0;
socket.Send(outData);
}
}
}