-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConnectionManager.cs
36 lines (32 loc) · 945 Bytes
/
ConnectionManager.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
using System;
using System.Net;
using System.Net.Sockets;
namespace Common
{
public class ConnectionManager
{
public static IPAddress LocalIPAddress { get { return IPAddress.Loopback; } }
public static int Port { get { return 42000; } }
public static IPEndPoint EndPoint { get { return new IPEndPoint(LocalIPAddress, Port); } }
public static Socket CreateListener()
{
Socket socket = null;
try
{
// Create a TCP/IP socket.
socket = CreateSocket();
socket.Bind(EndPoint);
socket.Listen(10);
}
catch (Exception)
{
throw;
}
return socket;
}
public static Socket CreateSocket()
{
return new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
}
}