public void Connect(IPEndPoint endpoint) { EndPoint = (endpoint as HotelEndPoint); if (EndPoint == null) { EndPoint = new HotelEndPoint(endpoint); } Client.Connect(endpoint); }
public void Intercept(HotelEndPoint endpoint) { listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listener.Bind(new IPEndPoint(IPAddress.Any, 38101)); listener.Listen(1); int interceptCount = 0; while (!IsConnected) { try { Local = new HNode(listener.Accept()); if (++interceptCount == SocketSkip) { interceptCount = 0; continue; } byte[] buffer = Local.Peek(6); Remote = HNode.ConnectNew(endpoint); if (BigEndian.ToUInt16(buffer, 4) == 4000) { IsConnected = true; OnConnected(EventArgs.Empty); _inSteps = 0; _outSteps = 0; Task.Factory.StartNew(InterceptOutgoing); Task.Factory.StartNew(InterceptIncoming); } else { buffer = Local.Receive(512); Remote.Send(buffer); buffer = Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<cross-domain-policy xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd\">" + "<allow-access-from domain=\"localhost\" to-ports=\"38101\"/>" + "</cross-domain-policy>\0"); Local.Send(buffer); continue; } } finally { if (!IsConnected) { Local?.Dispose(); Remote?.Dispose(); } } } }
public static bool TryParse(string host, int port, out HotelEndPoint endpoint) { try { endpoint = Parse(host, port); return(true); } catch { endpoint = null; return(false); } }
public void Intercept(string host, int port) { Intercept(HotelEndPoint.Parse(host, port)); }
public void Connect(string host, int port) { Connect(HotelEndPoint.Parse(host, port)); }
public static HNode ConnectNew(string host, int port) { return(ConnectNew(HotelEndPoint.Parse(host, port))); }