-
Notifications
You must be signed in to change notification settings - Fork 4
/
Client.cs
39 lines (34 loc) · 1.3 KB
/
Client.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
using System;
using System.Net;
using System.Net.Sockets;
namespace coc_proxy_csharp
{
public class Client : ClientCrypto
{
public ClientState state = new ClientState();
public Client(ServerState serverstate)
{
this.state.serverState = serverstate;
this.state.clientKey = this.clientKey;
this.state.serverKey = ClientCrypto.serverKey;
}
public void StartClient()
{
try
{
IPHostEntry ipHostInfo = Dns.GetHostEntry(Proxy.hostname);
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEndPoint = new IPEndPoint(ipAddress, Proxy.port);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
this.state.socket = socket;
socket.Connect(remoteEndPoint);
socket.BeginReceive(this.state.buffer, 0, State.BufferSize, 0, new AsyncCallback(Protocol.ReceiveCallback), this.state);
Console.WriteLine("Connected to {0} ...", socket.RemoteEndPoint.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}