/// <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); } } }
/// <summary> /// Called when the connected client socket has dispatched data. /// </summary> /// <param name="ar">The asynchronous result object for the asynchronous method.</param> private void OnConnectionSocketReceive(IAsyncResult ar) { try { if (connection != null && connection.Socket != null) { int received = connection.Socket.EndReceive(ar); if (received > 0) { if (destinationSocket != null) { destinationSocket.BeginSend(connectionBuffer, 0, received, SocketFlags.None, OnDestinationSocketSent, destinationSocket); } return; } } } catch { } Dispose(); }