/// <summary> /// 向对方发送数据 /// </summary> /// <param name="byteData">数据内容</param> /// <param name="clientID">连接标识</param> public void SendData(byte[] byteData, int clientID) { if (byteData.Length == 0) { return; } if (_tcpMode == TcpMode.Client) { if (!Connected) { onError(_localTcpStruct, _remoteTcpStruct, TcpError.TcpClientNotConnected, null, TcpOptionType.SendData, null); return; } _ns.Write(byteData, 0, byteData.Length); } else if (_tcpMode == TcpMode.Server) { __listen__readTcp pclinet = GetListenClient(clientID); if (pclinet != null) { pclinet.SendData(byteData); } else { onError(_localTcpStruct, _remoteTcpStruct, TcpError.TcpClientNotConnected, null, TcpOptionType.SendData, pclinet); } } else { onError(_localTcpStruct, _remoteTcpStruct, TcpError.UnknownModeOrNotConnected, null, TcpOptionType.SendData, null); } }
/// <summary> /// 关闭从监听创建的连接 /// </summary> /// <param name="clientID"></param> public void CloseConnect(int clientID) { __listen__readTcp reader = GetListenClient(clientID); try { if (reader != null) { reader.CloseConnect(); } } catch { } }
private void ReadDataFromListen() { _listenWork = true; while (_listenWork) { try { TcpClient _tc = _tl.AcceptTcpClient(); __listen__readTcp reader = new __listen__readTcp(this, ref _tc); lock (_tcp_Reader_Array) _tcp_Reader_Array.Add(reader); Threads.ExecAsync(reader.Start); } catch { } } }