설치한 패키지

SuperSocket.Channel 2.0.0-preview2-04

SuperSocket 2.0.0-preview1

SuperSocket.WebSocket on NuGet

Windows Service 설정

static void Main(string[] args)
{
	//If this application run in Mono/Linux, change the control script to be executable
	if ( Path.DirectorySeparatorChar == '/')
		ChangeScriptExecutable();

	var servicesToRun = new ServiceBase[]
	{
		new ServiceGame()
	};

	if (Environment.UserInteractive)
	{
		RunInteractiveServices(servicesToRun);
	}
	else
	{
		ServiceBase.Run(servicesToRun);
	}
}
static void RunInteractiveServices(ServiceBase[] servicesToRun)
{
	//LogSystem.Instance.RegistLog($"Start the services in interactive mode.", SYSTEM_LOG_LEVEL.MONITORING);

	// Get the method to invoke on each service to start it
	var onStartMethod = typeof(ServiceBase).GetMethod("OnStart", BindingFlags.Instance | BindingFlags.NonPublic);

	// Start services loop
	foreach (var service in servicesToRun)
	{
		//LogSystem.Instance.RegistLog($"Starting {service.ServiceName} ... ", SYSTEM_LOG_LEVEL.MONITORING);
		if (onStartMethod != null) onStartMethod.Invoke(service, new object[] {new string[] { }});
		//LogSystem.Instance.RegistLog($"Started", SYSTEM_LOG_LEVEL.MONITORING);
	}

	// Waiting the end
	Console.WriteLine("Press 'q' key to stop services et finish process...");
	var keyInfo = Console.ReadKey();
	while (keyInfo.Key != ConsoleKey.Q)
		keyInfo = Console.ReadKey();
	Console.WriteLine();

	// Get the method to invoke on each service to stop it
	var onStopMethod = typeof(ServiceBase).GetMethod("OnStop", BindingFlags.Instance | BindingFlags.NonPublic);

	// Stop loop
	foreach (var service in servicesToRun)
	{
		//LogSystem.Instance.RegistLog("Stopping {service.ServiceName} ... ");
		if (onStopMethod != null) onStopMethod.Invoke(service, null);
		//LogSystem.Instance.RegistLog("Stopped");
	}

	//LogSystem.Instance.RegistLog("All services are stopped.");

	// Waiting a key press to not return to VS directly
	if (!System.Diagnostics.Debugger.IsAttached) return;
	Console.WriteLine("=== Press a key to quit ===");
	Console.ReadKey();
}
private static void ChangeScriptExecutable()
{
	var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "supersocket.sh");

	try
	{
		if (!File.Exists(filePath))
			return;

		File.SetAttributes(filePath, (FileAttributes)((uint)File.GetAttributes(filePath) | 0x80000000));
	}
	catch
	{

	}
}