Thanks to visit codestin.com
Credit goes to github.com

Skip to content
George Michaelides edited this page Jul 3, 2020 · 12 revisions

Server Setup

Start / Close a server

      var server = new GemServer(profile: "DefaultProfile",
                                 new ServerConfig
                                 {
                                     Name = "MyServer",
                                     Port = 14242,
                                     EnableUPnP = false,
                                     MaxConnections = 10,
                                     Password = "1234",
                                     ConnectionTimeout = 5.0f,
                                     MaxConnectionAttempts = 5,
                                     RequireAuthentication = true
                                 },  
                                 PackageConfig.UDP);
      server.RunAsync();
      //...
      //...
      server.Disconnect();

Configure Behavior

OnIncomingConnection A client sends a connection approval message

OnClientDisconnect Someone disconnects

HandleNotifications A notification is received

  GemSever.Profile("GemChat")
          .OnIncomingConnection((server, connection, request)=>
          { 
              request.Message == "please!!!" ?
              connection.Approve() :
              connection.Deny();
          });

  GemSever.Profile("GemChat")
          .HandleNotifications((server, connection, notification)=>
          { 
              if(notification.Message == "how are you?")
              {
                  server.NotifyOnly(connection,"fine and you?")
              }
          });

Send Messages via Network Package

Simply by decorating your POCO class with the [NetworkPackage("profile")] attribute

More info about network packages

Register a command

      GemServer
     .RegisterCommand(command:"echo",
                      description:"Display Messages",
                      requiresAuthorization: false,
                      callback:(host, senderConnection, command,args) 
                      => host.SendToAll(args[0]));

Execute a Command

   GemServer.ExecuteCommand("echo i'm executing commands");
   GemServer.ExecuteCommand(sender, "i'm remotely executing commands");
Clone this wiki locally