-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackClient.cs
More file actions
62 lines (52 loc) · 1.47 KB
/
Copy pathStackClient.cs
File metadata and controls
62 lines (52 loc) · 1.47 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace NetworkingStack.Client
{
public class StackClient : Core.EncryptedNetworkStack
{
private static readonly int sendBufferSize = 64 * 1024;
private static readonly int receiveBufferSize = 64 * 1024;
public StackClient() : base()
{
Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
{
ReceiveBufferSize = sendBufferSize,
SendBufferSize = receiveBufferSize,
};
}
public bool Connect(IPAddress address, ushort port)
{
try
{
Socket.Connect(address, port);
}
catch (Exception ex)
{
Console.WriteLine(ex);
return false;
}
this.OpenAsClient();
return Socket.Connected;
}
public bool Connect(string host, ushort port)
{
IPAddress[] ipAddresses = Dns.GetHostAddresses(host);
foreach (IPAddress ipAddress in ipAddresses)
{
if (Connect(ipAddress, port))
{
break;
}
}
if (!Socket.Connected)
{
OnStatusChange(0);
}
return Socket.Connected;
}
}
}