forked from tmoonlight/NSmartProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSPClient.cs
More file actions
75 lines (63 loc) · 1.84 KB
/
NSPClient.cs
File metadata and controls
75 lines (63 loc) · 1.84 KB
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
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
namespace NSmartProxy
{
public class NSPClient
{
public int ClientID;
public DateTime LastUpdateTime;
public TcpClient ConfigClient; //配置用的socket
public Dictionary<int, NSPApp> AppMap; //Appid->app
public NSPClient()
{
AppMap = new Dictionary<int, NSPApp>();
}
/// <summary>
/// 注册app并且返回appid(非线程安全)
/// </summary>
/// <returns></returns>
public int RegisterNewApp()
{
//按顺序分配最大int
int preAppId = 1;
if (AppMap.Count > 0)
preAppId = AppMap.Last().Key + 1;
NSPApp app = this.AppMap[preAppId] = new NSPApp()
{
AppId = preAppId,
ClientId = ClientID
};
return app.AppId;
}
/// <summary>
/// 绑定主机头host到某个端口上,同一端口可以多次绑定
/// </summary>
/// <param name="host"></param>
/// <param name="port"></param>
/// <returns></returns>
//public int BindHost(string host, int port)
//{
// if (AppMap[port].HttpApps.Count == 0)
// {
// AppMap.
// }
// AppMap[port].HttpApps.
//}
public NSPApp GetApp(int appId)
{
return AppMap[appId];
}
//public int Close()
//{
// //统计关闭的连接数
// int ClosedConnectionCount = 0;
// foreach (var AppKV in AppMap)
// {
// ClosedConnectionCount += AppKV.Value.Close();
// }
// return ClosedConnectionCount;
//}
}
}