public void Disconnected(TcpExchangeHub hub, TcpRelayDirection direction) { foreach (var logger in this._loggers) { logger.Disconnected(hub, direction); } }
public void TransmitData(TcpExchangeHub hub, TcpRelayDirection direction, byte[] data, int count) { foreach (var logger in this._loggers) { logger.TransmitData(hub, direction, data, count); } }
private static void Main(string[] args) { EnvironmentOptions options = BuildEnvironmentOptions(args); if (options == null) { return; } IPAddress ipAddress = IPAddress.Any; var listeningSocket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.IP); listeningSocket.Bind(new IPEndPoint(ipAddress, options.ListenOnPort)); listeningSocket.Listen(0); var logger = BuildLogger(options); AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => logger.ShuttingDown(); while (true) { Socket clientSocket = null; Socket relaySocket = null; Task <Socket> .Factory.FromAsync(listeningSocket.BeginAccept, listeningSocket.EndAccept, null) .ContinueWith(task => { clientSocket = task.Result; return(Task <IPHostEntry> .Factory.FromAsync(Dns.BeginGetHostEntry, Dns.EndGetHostEntry, options.ForwardToHostAddress, null)); }) .Unwrap() .ContinueWith(task => { IPHostEntry relayHostEntry = task.Result; IPAddress relayHostIpAddress = relayHostEntry.AddressList.First(); relaySocket = new Socket(relayHostIpAddress.AddressFamily, SocketType.Stream, ProtocolType.IP); return(Task.Factory.FromAsync(relaySocket.BeginConnect, relaySocket.EndConnect, relayHostEntry.AddressList, options.ForwardToPort, null)); }) .Unwrap() .ContinueWith(task => { var exchange = new TcpExchangeHub(logger); exchange.WireExchange(relaySocket, clientSocket); }) .Wait(); } }
public void ClientConnected(TcpExchangeHub hub) { foreach (var logger in this._loggers) { logger.ClientConnected(hub); } }
public void Disconnected(TcpExchangeHub hub, TcpRelayDirection direction) { if (direction == TcpRelayDirection.ClientToRelay) { Interlocked.Decrement(ref this._connectedClients); } }
public void TransmitData(TcpExchangeHub hub, TcpRelayDirection direction, byte[] data, int count) { var hex = new string[data.Length]; var charRep = new string[count]; for (int i = 0; i < data.Length; i++) { hex[i] = " "; } for (int i = 0; i < count; i++) { var c = (char)data[i]; hex[i] = data[i].ToString("X2"); charRep[i] = (char.IsControl(c) || char.IsWhiteSpace(c)) ? "." : c.ToString(CultureInfo.InvariantCulture); } string info = string.Format("{0} {1}", string.Join(" ", hex), string.Join(" ", charRep) ); this.WriteLine(hub, direction, info); }
private static void WriteLine(TcpExchangeHub hub, TcpRelayDirection direction, string information) { Console.WriteLine("{0:HH:mm:ss.ff} {1} {2} {3}", DateTime.Now, TcpDataLoggerHelper.GetDirectionShortCode(direction), TcpDataLoggerHelper.GetShortInstanceName(hub), information); }
public void TransmitData(TcpExchangeHub hub, TcpRelayDirection direction, byte[] data, int count) { var hex = new string[count]; for (int i = 0; i < count; i++) { hex[i] = data[i].ToString("X2"); } string info = string.Join(" ", hex); WriteLine(hub, direction, info); }
public void TransmitData(TcpExchangeHub hub, TcpRelayDirection direction, byte[] data, int count) { if (!this._transmissionSubject.HasObservers) { return; } var subject = new TransmissionSummary { Hub = hub, ByteCount = count, Direction = direction, }; this._transmissionSubject.OnNext(subject); }
private void WriteLine(TcpExchangeHub hub, TcpRelayDirection direction, string message) { this.EnsureIsInitialized(); DateTime dt = DateTime.Now; lock (this._lockObject) { this._fileWriter.WriteLine("{0:yyyy-MM-dd HH:mm:ss.fff} {1} {2}+ {3}", dt, TcpDataLoggerHelper.GetShortInstanceName(hub), TcpDataLoggerHelper.GetDirectionShortCode(direction), message ); } }
public void ClientConnected(TcpExchangeHub hub) { Interlocked.Increment(ref this._connectedClients); }
public void ClientConnected(TcpExchangeHub hub) { string information = string.Format("Client Connected from {0}", hub.ClientEndPoint); WriteLine(hub, TcpRelayDirection.ClientToRelay, information); }
public void Disconnected(TcpExchangeHub hub, TcpRelayDirection direction) { WriteLine(hub, direction, "Disconnected"); }