-
Notifications
You must be signed in to change notification settings - Fork 12
/
Listener.cs
43 lines (37 loc) · 909 Bytes
/
Listener.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace CentralMine.NET
{
class Listener
{
TcpListener mSocket;
Thread mThread;
ClientManager mTheMan;
public Listener(int port, ClientManager manager)
{
mTheMan = manager;
mSocket = new TcpListener(IPAddress.Any, port);
mThread = new Thread(new ThreadStart(ListenLoop));
mThread.Start();
}
public void Close()
{
mSocket.Stop();
mThread.Abort();
}
void ListenLoop()
{
mSocket.Start();
while (true)
{
TcpClient client = mSocket.AcceptTcpClient();
mTheMan.AcceptClient(client);
}
}
}
}