-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerApi.cs
52 lines (44 loc) · 861 Bytes
/
ServerApi.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
using System;
using System.Net;
using System.Net.Sockets;
using AsyncServerImpl;
using SyncServerImpl;
namespace socketwrap
{
public enum SyncEnum { Async, Sync }
public interface ITestServer
{
public static ITestServer Create(bool async, int max_conn, int port,
IMessageHandler mh)
{
if(async)
{
return new AsyncServerImpl(max_conn, port, mh);
}
else
{
return new SyncServerImpl(max_conn, port, mh);
}
}
void Serve();
}
public class Message
{
public Socket m_socket = null;
public const int m_buf_size = 1024;
public byte[] m_buf = new byte[m_buf_size];
public StringBuilder m_sb = new StringBuilder();
Message(Socket s)
{
m_socket = s;
}
}
public class ReplyMessage : Message
{
public bool m_quit;
}
public interface IMessageHandler
{
ReplyMessage Handle(Message m);
}
}