-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
67 lines (52 loc) · 1.77 KB
/
Program.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
using CommandLine;
using System;
namespace EchoServer
{
class Program
{
static void Main(string[] args)
{
// dotnet EchoServer.dll --port 12021 --maxConnectionNumber 32 --name EchoServer
Console.WriteLine("Hello SuperSocketLite");
var serverOption = ParseCommandLine(args);
if (serverOption == null)
{
return;
}
var server = new MainServer();
server.InitConfig(serverOption);
server.CreateServer();
var IsResult = server.Start();
if (IsResult)
{
MainServer.MainLogger.Info("서버 네트워크 시작");
}
else
{
Console.WriteLine("[ERROR] 서버 네트워크 시작 실패");
return;
}
MainServer.MainLogger.Info("key를 누르면 종료한다...");
Console.ReadKey();
}
static ServerOption ParseCommandLine(string[] args)
{
var result = CommandLine.Parser.Default.ParseArguments<ServerOption>(args) as CommandLine.Parsed<ServerOption>;
if (result == null)
{
Console.WriteLine("Failed Command Line");
return null;
}
return result.Value;
}
}
public class ServerOption
{
[Option("port", Required = true, HelpText = "Server Port Number")]
public int Port { get; set; }
[Option("maxConnectionNumber", Required = true, HelpText = "MaxConnectionNumber Count")]
public int MaxConnectionNumber { get; set; } = 0;
[Option("name", Required = true, HelpText = "Server Name")]
public string Name { get; set; }
}
}