-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (41 loc) · 1.66 KB
/
Copy pathProgram.cs
File metadata and controls
53 lines (41 loc) · 1.66 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
using System;
using System.Diagnostics;
using System.Threading;
namespace TCPServerApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to TCP Remote Server");
if (args.Length < 2) Exit();
else if (!args[0].ToLower().Equals("--authtoken") || string.IsNullOrEmpty(args[1])) Exit();
string ngrok_auth_token = args[1].Trim();
//kill any ngrok process already running in the background
foreach (var process in Process.GetProcessesByName("ngrok"))
process.Kill();
ServerListener server = new ServerListener();
Ngrok ngrok = new Ngrok();
ngrok.AuthToken = ngrok_auth_token;
ngrok.Start(server.TCPPort); //ngrok has created a tcp tunnel to local interface
//ngrok process is a blocking thread so its async. Delay for 2 secs to complete propagation
Thread.Sleep(2000);
//retrieve the public channel from ngrok API
ngrok.PublicUrl().Wait();
//start the local TCP server
server.StartListening()
.Wait(); //listen indefinitely until a .quit message is received
//kill internal ngrok thread
ngrok.process.Kill();
//Console.Read();
}
static void Exit()
{
Console.WriteLine("You provided invalid arguments.");
Console.WriteLine("Usage: specify your ngrok authtoken using --authtoken ");
Console.WriteLine("Press any key to exit");
Console.Read();
Process.GetCurrentProcess().Kill();
}
}
}