/// <summary> /// The connect. /// </summary> /// <param name="host"> /// The host. /// </param> /// <param name="port"> /// The port. /// </param> /// <returns> /// The <see cref="ISCommClient"/>. /// </returns> public bool Connect(string host, int port) { if (this.tcpClient.Connected == false) { try { this.tcpClient.Connect(host, port); this.stream = new ISCommStream(this.tcpClient); this.stream.NetworkStream.WriteTimeout = this.sendTimeout; this.stream.NetworkStream.ReadTimeout = this.receiveTimeout; this.stream.ObjectReceived += this.StreamObjectReceived; this.stream.BeginReceive(); return(true); } catch (SocketException socketException) { if (socketException.ErrorCode == 10056) { // One immediate retry only this.tcpClient.Close(); this.tcpClient = new TcpClient(); this.tcpClient.Connect(host, port); } } } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="Session"/> class. /// </summary> /// <param name="sessions"> /// The sessions. /// </param> /// <param name="bus"> /// The bus. /// </param> /// <param name="tcpClient"> /// The tcp client. /// </param> public Session(Sessions sessions, ITinyMessengerHub bus, TcpClient tcpClient) { this.client = tcpClient; this.stream = new ISCommStream(tcpClient); this.stream.ObjectReceived += this.StreamObjectReceived; this.bus = bus; this.sessions = sessions; this.stream.BeginReceive(); }