-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProxyConnection.cs
82 lines (67 loc) · 1.82 KB
/
ProxyConnection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Net.Sockets;
using System.Net;
using System.IO;
namespace WinProxy
{
/// <summary>
/// Summary description for ProxyConnection.
/// </summary>
public class ProxyConnection
{
public int connNumber;
public bool m_bHttpsClient;
public bool m_bHttpsServer;
public bool isShutdown = false;
public TcpClient clientSocket; //socket for communication with the client
public Stream clientStream; //Networkstream or SslStream
public string serverName;
public int serverPort;
public TcpClient serverSocket; //Socket for communication with the server
public Stream serverStream;
public const int BUFFER_SIZE = 8092;
public byte[] clientReadBuffer = new byte[BUFFER_SIZE];
public byte[] serverReadBuffer = new byte[BUFFER_SIZE];
public int clientNumBytes;
public byte[] clientSendBuffer = new byte[BUFFER_SIZE];
public int serverNumBytes;
public byte[] serverSendBuffer = new byte[BUFFER_SIZE];
public ProxyConnection(bool bHttpsClient, bool bHttpsServer)
{
m_bHttpsClient = bHttpsClient;
m_bHttpsServer = bHttpsServer;
}
public void disconnect()
{
isShutdown = true;
try
{
if (serverSocket != null)
{
serverSocket.Close();
}
if (clientSocket != null)
{
clientSocket.Close();
}
}
catch (SocketException se)
{
WinTunnel.WriteTextToConsole(string.Format("Socket Error occurred while shutting down sockets: {0}.", se));
}
catch (Exception e)
{
WinTunnel.WriteTextToConsole(string.Format("Error occurred while shutting down sockets: {0}.", e));
}
finally
{
serverSocket = null;
clientSocket = null;
clientReadBuffer = null;
clientSendBuffer = null;
serverReadBuffer = null;
serverSendBuffer = null;
}
}
}
}