/// <summary> /// A Proxy constructor that takes in the /// string and port name to create a Tcp connection. /// </summary> /// <param name="r">An Abstract Receiver</param> /// <param name="s">An Abstract Sender</param> /// <param name="host">host name for tcp</param> /// <param name="port">port number for tcp</param> /// <param name="id">the id of the proxy</param> public Proxy(AbstractReceiver r, AbstractSender s, string host, int port, int id) { _logger = Logger.LogInstance; try { // this is not supported for .NET core... // this.client = new TcpClient(host, port); _client = new TcpClient(); Id = id; IPAddress ipAddress = IPAddress.Parse(host); // wait for the client to connect for a few seconds var success = _client.ConnectAsync(ipAddress, port) .Wait(NetworkSendReceive.NetworkTimeout); if (!success) { return; } } catch (SocketException e) { _logger.Log(e.ToString()); return; // should stop or throw exception // without the socket no communication // will happen } IOStream = _client.GetStream(); _receiver = r; _sender = s; ConfigureSenderReceiver(); }
/// <summary> /// Hand off the sender and receiver to a new /// sender and receiver object. /// </summary> /// <param name="r">new receiver</param> /// <param name="s">new sender</param> /// <param name="c">the connection type</param> public void HandOffSendReceive(AbstractReceiver r, AbstractSender s, ConnectionType c) { _receiver = r; _sender = s; Connection = c; // reconfigure ConfigureSenderReceiver(); }
/// <summary> /// A Proxy constructor that can be passed /// an already initalized TcpClient. /// </summary> /// <param name="r">An Abstract Receiver</param> /// <param name="s">An Abstract Sender</param> /// <param name="client">An initalized TcpClient</param> /// <param name="id">the id of the proxy</param> public Proxy(AbstractReceiver r, AbstractSender s, TcpClient client, int id) { _logger = Logger.LogInstance; _client = client; Id = id; IOStream = client.GetStream(); _receiver = r; _sender = s; ConfigureSenderReceiver(); }