public NetLibServer(IPAddress localaddr, int port, TransferProtocolType protocol, Encoding encoding) { Protocol = new TransferProtocolFactory().CreateTransferProtocol(protocol, encoding, new Action<string>(Log)); if (protocol == TransferProtocolType.Delimited) { Delimiter = new byte[] { 13, 10 }; } Listener = new TcpListener(localaddr, port); }
public async Task Connect(string hostname, int port, TransferProtocols protocol, Encoding encoding) { Protocol = new TransferProtocolFactory().CreateTransferProtocol(protocol, encoding, new Action <string>(Log)); Protocol.AddEventCallbacks(OnDataAvailable, OnBytesAvailable); Client = new TcpClient(); Task t = Client.ConnectAsync(hostname, port); await t; NetworkStream stream = Client.GetStream(); buffer = new byte[Client.ReceiveBufferSize]; stream.BeginRead(buffer, 0, buffer.Length, ReadCallback, Client); }
public NetLibClient(TransferProtocolType protocolType, Encoding encoding, IPEndPoint localEndPoint = null, int readLoopSleepTime = 50) { ReadLoopSleepTime = readLoopSleepTime; protocol = new TransferProtocolFactory().CreateTransferProtocol(protocolType, encoding, new Action<string>(Log)); if (localEndPoint != null) { Client = new TcpClient(localEndPoint); } else { Client = new TcpClient(); } Delimiter = new byte[] { 13, 10 }; ++clientCount; }
public NetLibServer(IPAddress localaddr, int port, TransferProtocols protocol, Encoding encoding) { Protocol = new TransferProtocolFactory().CreateTransferProtocol(protocol, encoding, new Action <string>(Log)); Listener = new TcpListener(localaddr, port); }