/// <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); }
/// <summary> /// 创建线程对象 /// </summary> /// <param name="action">线程要执行的委托</param> /// <param name="name">线程名称</param> /// <param name="isBackground">是否后台运行[true:后台线程;false:前台线程]</param> /// <param name="obj">线程启动参数</param> /// <returns>返回线程对象</returns> public static IThreadEx Start(Action <ThreadExPara> action, string name = null, bool isBackground = true, object obj = null) { var thread = new ThreadEx(action, name, isBackground); thread.Start(obj); return(thread); }
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(); }
private void CreateProcessThread() { if (!this._allowAddThread) { return; } if (!this._allowAddThread) { return; } if (this._isDisposed) { this._allowAddThread = false; return; } if (this._threadList.Count >= Environment.ProcessorCount) { this._allowAddThread = false; return; } if (this._addProcessThreadConditionType) { if (!this._addProcessThreadFunc(this._threadList.Count)) { this._allowAddThread = false; return; } } else { if (this._maxThreadCount > 0 && this._threadList.Count >= this._maxThreadCount) { this._allowAddThread = false; return; } } string threadName = $"{this._threadNamePre}{this._threadList.Count}"; ThreadEx thread = new ThreadEx(this.ProcessThreadMethod, threadName, true); this._threadList.Add(thread); thread.Start(); }
/// <summary> /// 服务端构造函数 /// </summary> /// <param name="pipeName">管道名称</param> /// <param name="proFunc">处理回调</param> /// <param name="readDataMillisecondsTimeout">读取数据超时时长,默认5000毫秒,小于等于-1,死等</param> public NamedPipeEx(string pipeName, Func <byte[], byte[]> proFunc, int readDataMillisecondsTimeout = 5000) { if (string.IsNullOrWhiteSpace(pipeName)) { throw new ArgumentNullException(nameof(pipeName)); } if (proFunc == null) { throw new ArgumentNullException(nameof(proFunc)); } this._pipeName = pipeName; this._readDataMillisecondsTimeout = readDataMillisecondsTimeout; this._proFunc = proFunc; this._listenThread = new ThreadEx(ListenThreadMethod, $"管道{pipeName}监听线程", true); this._listenThread.Start(); }