private void HandleError(ITcpConnection conn, SocketError err) { // assume that any connection error means that the Host isn't running, yet. Just wait // a second and try again. TcpConnection.Clear(); //client should only have one connection Thread.Sleep(1000); Log.Debug("TcpBusClientSide call to CreateConnectingTcpConnection() failed - SocketError= " + err + " - retrying."); TcpConnection.Add(CreateTcpConnection(CommandEndpoint)); }
public TcpBusClientSide( IDispatcher messageBus, IPAddress hostIP, int commandPort, ITcpConnection tcpConnection = null) : base(hostIP, commandPort, messageBus) { TcpConnection.Add(tcpConnection ?? CreateTcpConnection(CommandEndpoint)); }
public TcpBusClientSide( IDispatcher messageBus, EndPoint endpoint, ITcpConnection tcpConnection = null, IMessageSerializer messageSerializer = null) : base(endpoint, messageBus, messageSerializer) { TcpConnection.Add(tcpConnection ?? CreateTcpConnection(CommandEndpoint)); }
public TcpBusServerSide( IPAddress hostIp, int commandPort, IDispatcher messageBus, IMessageSerializer messageSerializer = null) : base(hostIp, commandPort, messageBus, messageSerializer) { Log.Info("ConfigureTcpListener(" + CommandEndpoint.AddressFamily + ", " + CommandEndpoint + ") entered."); var listener = new TcpServerListener(CommandEndpoint); listener.StartListening((endPoint, socket) => { var conn = Transport.TcpConnection.CreateAcceptedTcpConnection(Guid.NewGuid(), endPoint, socket, verbose: true); LengthPrefixMessageFramer framer = new LengthPrefixMessageFramer(); framer.RegisterMessageArrivedCallback(TcpMessageArrived); Action <ITcpConnection, IEnumerable <ArraySegment <byte> > > callback = null; callback = (x, data) => { try { framer.UnFrameData(data); } catch (PackageFramingException exc) { Log.ErrorException(exc, "LengthPrefixMessageFramer.UnFrameData() threw an exception:"); // SendBadRequestAndClose(Guid.Empty, string.Format("Invalid TCP frame received. Error: {0}.", exc.Message)); return; } conn.ReceiveAsync(callback); }; conn.ReceiveAsync(callback); TcpConnection.Add(conn); }, "Standard"); Log.Info("ConfigureTcpListener(" + CommandEndpoint.AddressFamily + ", " + CommandEndpoint + ") successfully constructed TcpServerListener."); _commandPortListener = listener; }