public bool Write(ITcpSessionContext tcpContext, byte[] data) { if (!(tcpContext.NetworkStream?.CanWrite ?? false)) { tcpContext.IsSessionAlive = false; tcpContext.NetworkStream?.Dispose(); return(false); } tcpContext.NetworkStream.Write(data); return(true); }
public bool ReadNext(ITcpSessionContext tcpContext, ITcpCommandController sender) { if (!(tcpContext.NetworkStream?.CanRead ?? false)) { tcpContext.IsSessionAlive = false; tcpContext.NetworkStream?.Dispose(); return(false); } var recvBuffer = new byte[BufferLength]; while (!tcpContext.NetworkStream.DataAvailable) { Thread.Yield(); } var count = tcpContext.NetworkStream.Read(recvBuffer, 0, recvBuffer.Length); //string rr = recvBuffer.Take(count).Select(c => c.ToString()).Aggregate((a, b) => a + " " + b); //LoggerFactory.GetLogger().Print(rr); sender.OnTcpReceive(recvBuffer, 0, count); return(true); }
public TcpCommandController(ITcpController tcpController, ITcpSessionContext sessionContext, IEntityProviderFactory entityProviderFactory) { _tcpController = tcpController; _sessionContext = sessionContext; _entityProviderFactory = entityProviderFactory; }