/// <summary> /// 构造函数 /// </summary> /// <param name="proCallback">接收命令回调</param> /// <param name="serviceName">回显名称</param> /// <param name="authInfo">登录认证信息</param> /// <param name="ip">监听IP</param> /// <param name="port">监听端口</param> /// <param name="backlog">客户最大连接数</param> public TelnetServer(Func <string, string> proCallback, string serviceName, TelnetAuthInfo authInfo = null, IPAddress ip = null, int port = 64000, int backlog = 3) { if (authInfo == null) { authInfo = new TelnetAuthInfo(); } if (ip == null) { ip = IPAddress.Parse("0.0.0.0"); } this._tcpListener = new TcpListener(ip, port); this._tcpListener.Start(backlog); //this._listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //this._listenerSocket.Bind(new IPEndPoint(ip, port)); //if (backlog < 1) //{ // backlog = 1; //} //this._listenerSocket.Listen(backlog); this._serviceName = serviceName; this._authInfo = authInfo; this._proCallback = proCallback; this._thread = new ThreadEx(this.StartListen, "TelnetServer监听线程", true); }
public TelnetClient(TelnetAuthInfo authInfo, string serviceName, Socket client, Func <string, string> proCallback, Action <TelnetClient> clientClose) { this._authInfo = authInfo; this._isLogined = !authInfo.IsAuth; this._serviceName = serviceName; this._client = client; this._proCallback = proCallback; this._clientClose = clientClose; this._target = Encoding.Default.GetBytes(_newLine); this._receiveThread = new ThreadEx(this.RecieveMethod, "", true); this._receiveQueue = new AsynQueue <byte[]>(this.ProThreadMethod, "", true, true); this._receiveThread.Start(); }