CSHARP   34

XSocketsServer

Guest on 24th November 2022 01:34:40 AM

  1. using System;
  2. using System.Diagnostics;
  3. using XSockets.Core.Common.Socket;
  4. using XSockets.Core.Common.Socket.Event.Arguments;
  5. using XSockets.Plugin.Framework;
  6. using XSockets.Plugin.Framework.Helpers;
  7. using Toolbox;
  8. using System.Net;
  9.  
  10. namespace H_Man
  11. {
  12.   public class XSocketsServer
  13.   {
  14.     private IXSocketServerContainer server = null;
  15.  
  16.     public XSocketsServer()
  17.     {
  18.       this.server = Composable.GetExport<IXSocketServerContainer>();
  19.  
  20.       this.server.OnServersStarted += server_OnServersStarted;
  21.       this.server.OnServersStopped += server_OnServersStopped;
  22.  
  23.       this.server.OnError += server_OnError;
  24.     }
  25.  
  26.     public void Start()
  27.     {
  28.       this.server.StartServers();  
  29.     }
  30.  
  31.     public void Stop()
  32.     {
  33.       this.server.StopServers();
  34.     }
  35.  
  36.     private void server_OnError(object sender, XSockets.Core.Common.Socket.Event.Arguments.OnErrorArgs e)
  37.     {
  38.       Console.WriteLine("H-Man: Error: " + e.Exception.Message);
  39.       Console.WriteLine("H-Man: Error: " + e.Exception.StackTrace);
  40.     }
  41.  
  42.     private void server_OnServersStopped(object sender, EventArgs e)
  43.     {
  44.       foreach (IXSocketServer s in server.Servers)
  45.       {
  46.         Console.WriteLine("H-Man: Stopped server " +  s.ConfigurationSetting.Port);
  47.       }
  48.     }
  49.  
  50.     private void server_OnServersStarted(object sender, EventArgs e)
  51.     {
  52.       foreach (IXSocketServer s in server.Servers)
  53.       {
  54.         Console.WriteLine("H-Man: Started server " + s.ConfigurationSetting.Port);
  55.       }
  56.     }
  57.   }
  58. }

Raw Paste


Login or Register to edit or fork this paste. It's free.