using System; using System.IO; using System.Net.Sockets; using System.Text; namespace Team.Communicate.State { public class TcpClientState { public TcpClient TcpClient { get; } public Encoding Encoding { get; set; } /// /// 获取缓冲区 /// public byte[] Buffer { get; private set; } /// /// 缓存数据写入内存流 /// public MemoryStream Memory { get; set; } /// /// 获取网络流 /// public NetworkStream NetworkStream => TcpClient.GetStream(); public TcpClientState(TcpClient tcpClient, byte[] buffer) { TcpClient = tcpClient ?? throw new ArgumentNullException(nameof(tcpClient)); Buffer = buffer ?? throw new ArgumentNullException(nameof(buffer)); Memory = new MemoryStream(); Encoding=Encoding.Default; } /// /// 关闭 /// public void Close() { //关闭数据的接受和发送 TcpClient.Close(); Memory.Close(); Buffer = null; } } }