/// <summary> /// Called when the forwarding socket has connected to the proxy connection. /// </summary> /// <param name="ar">The asynchronous result object for the asynchronous method.</param> private void OnSocketConnected(IAsyncResult result) { try { destinationSocket.EndConnect(result); if (connection.Method.StartsWith("CONNECT", StringComparison.CurrentCultureIgnoreCase)) { connection.Write("{0} 200 Connection established\r\nProxy-Agent: Tor Socks5 Proxy\r\n\r\n", connection.HTTP); } else { string header = connection.GetHeader(); destinationSocket.Send(Encoding.ASCII.GetBytes(header)); if (connection.Post != null) { destinationSocket.Send(connection.Post); } } ExchangeBuffers(); } catch (Exception exception) { throw new TorException("The connection processor failed to finalize instructions", exception); } }
/// <summary> /// Called when the forwarded socket has connected to the destination IP address and port. /// </summary> /// <param name="ar">The asynchronous result object for the asynchronous method.</param> private void OnSocketConnect(IAsyncResult ar) { try { buffer[0] = 5; buffer[1] = 1; buffer[2] = 0; socket.EndConnect(ar); socket.BeginSend(buffer, 0, 3, SocketFlags.None, OnSocketSendHandshake, socket); } catch { if (callback != null) { callback(false); } } }