-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (51 loc) · 2.12 KB
/
Program.cs
File metadata and controls
59 lines (51 loc) · 2.12 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
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace MLAPI.Puncher.Client.Console
{
class Program
{
public const string PUNCHER_SERVER_HOST = "puncher.midlevel.io";
public const int PUNCHER_SERVER_PORT = 6776;
static void Main(string[] args)
{
Task listenTask = Task.Factory.StartNew(() =>
{
try
{
using (PuncherClient listenPeer = new PuncherClient(PUNCHER_SERVER_HOST, PUNCHER_SERVER_PORT))
{
System.Console.WriteLine("[LISTENER] Listening for single punch on our port 1234...");
IPEndPoint endpoint = listenPeer.ListenForSinglePunch(new IPEndPoint(IPAddress.Any, 1234));
System.Console.WriteLine("[LISTENER] Connector: " + endpoint + " punched through our NAT");
}
}
catch (Exception e)
{
System.Console.WriteLine(e);
}
});
// Wait a bit to make sure the listener has a chance to register.
Thread.Sleep(1000);
System.Console.Write("[CONNECTOR] Enter the address of the listener you want to punch: ");
string address = System.Console.ReadLine();
using (PuncherClient connectPeer = new PuncherClient(PUNCHER_SERVER_HOST, PUNCHER_SERVER_PORT))
{
System.Console.WriteLine("[CONNECTOR] Punching...");
if (connectPeer.TryPunch(IPAddress.Parse(address), out IPEndPoint connectResult))
{
System.Console.WriteLine("[CONNECTOR] Punched through to peer: " + connectResult);
}
else
{
System.Console.WriteLine("[CONNECTOR] Failed to punch");
}
// Prevent application from exiting before listener has ended
listenTask.Wait();
}
// For the plebs
System.Console.Read();
}
}
}