static void Main(string[] args)
        {
            // Notes about Port 2225: For this port exist no active reservations from the IANA.
            // Additionally no special permissions are required
            NetComServer server = new NetComServer(2225);

            server.Debug         = NetComDebugOutput.ToConsole;
            server.EncodeMessage = NetComMessageEncoder.Default;
            server.ParseMessage  = NetComMessageParser.Default;
            server.LibraryExec   = NetComLibraryExecuter.Default;

            server.Init();
            server.Start();
            server.EnableProcessing();
            server.EnableSending();

            int i = 0;

            while (i < 100)
            {
                server.SendToClient("[MyData:MyValue];[MyData2:MyValue2]", 0);
                //server.Broadcast("[[UI i is brotkastl]]");

                Thread.Sleep(3000);
            }

            Console.ReadLine();
        }
Exemple #2
0
#pragma warning disable IDE0060 // unused parameters
        static void Main(string[] args)
        {
            Console.Title           = "Server";
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("===================================");
            Console.WriteLine("=            S E R V E R          =");
            Console.WriteLine("===================================\r\n");
            Console.ForegroundColor = ConsoleColor.White;


            //NetComServerHandler serverHandler = new NetComServerHandler(2225);
            //NetComServer server = serverHandler.GetServer();

            ServerHandler serverHandler = new ServerHandler(2225);

            serverHandler.SetDebugOutput(DebugOutput.ToConsole);

            serverHandler.SetAuthenticationTool(AuthenticationTools.DebugAuth);

            serverHandler.Start();

            // The server can send to a range of connected clients, wich can be selected in the server.ConnectedClients-Property

            Thread.Sleep(2000);

            NetComServer server = serverHandler.GetServer();

            server.UserGroups.NewGroup("Awesome dudes");
            server.UserGroups["Awesome dudes"].AddUser("Tobias");
            server.UserGroups["Awesome dudes"].AddUser("Adam");

            //server.UserGroups.Load(@"C:\Users\zivi\Desktop\test.dat");

            while (true)
            {
                Console.Title = $"Server  -  Send: {serverHandler.HandlerData.LogSendCounter}     Receive: {serverHandler.HandlerData.LogReceiveCounter}";
                server.Send(new ILE.TestSample(server, server.ConnectedClients[new Random().Next(0, server.ConnectedClients.Count)]));

                Thread.Sleep(2000);

                Console.Title = $"Server  -  Send: {serverHandler.HandlerData.LogSendCounter}     Receive: {serverHandler.HandlerData.LogReceiveCounter}";
                server.GroupSend(new ILE.TestSample(server, null), server.UserGroups["Awesome dudes"]);

                Thread.Sleep(2000);

                Console.Title = $"Server  -  Send: {serverHandler.HandlerData.LogSendCounter}     Receive: {serverHandler.HandlerData.LogReceiveCounter}";
                server.Broadcast(new ILE.TestSample(server, null));

                Thread.Sleep(2000);
            }



#pragma warning disable 0162 // unreachable code
            Console.ReadKey();
#pragma warning restore 0162 // unreachable code
        }
        static void Main(string[] args)
        {
            // UserGroups can be used to manage clients that are connected (and not connected)
            // to the server, by putting them into groups.
            // A single client can be assigned to any number of groups.

            // Create the server
            NetComServer server = new NetComServer(2225);

            server.SetDebugOutput(DebugOutput.ToConsole);
            server.SetAuthenticationTool(AuthenticationTools.FullAllow);

            // Load previously created groups and their users into memory.
            server.UserGroups.Load(@"Path\To\Your\Config\File");

            // Start the server
            server.Start();

            // Create a new user-group (if it doesn't existent yet)
            server.UserGroups.NewGroup("SampleUserGroup");

            // Add users to the user-group
            // Users can be added if they are online or offline with the username.
            // No matter how they get added the first time, they will allways get reassigned
            // to this group when they connect unless they get removed from the group.

            // Adding a already connected user
            server.UserGroups["SampleUserGroup"].AddUser(server.ConnectedClients[6]);

            // Adding a user by its username
            server.UserGroups["SampleUserGroup"].AddUser("SomeUsername");

            // By using the Disconnect-Method, the user gets excluded from the group until
            // he reconnects. This does not permanently remove the user from the group.
            server.UserGroups["SampleUserGroup"].Disconnect(server.ConnectedClients[2]);

            // To completely remove a user from a group, use the Remove-Method.
            // When removing a user, it stays connected until it disconnects, but it will not get
            // re-assigned to the group again.
            server.UserGroups["SampleUserGroup"].Remove("AnotherUsername");

            // To save the group-configuration to a file, use the Save-Method
            server.UserGroups.Save(@"Path\To\Your\Config\File");
        }
Exemple #4
0
        static void Main(string[] args)
        {
            NetComServer server = new NetComServer(2225);

            server.Debug         = NetComDebugOutput.ToConsole;
            server.ParseMessage  = NetComMessageParser.DefaultServer;
            server.EncodeMessage = NetComMessageEncoder.DefaultServer;
            server.AuthLookup    = NetComAuthLookup.MySQL;

            server.Start(); // Listening starts with server.Start();

            int i = 0;

            while (true)
            {
                server.SendToClientRSA(0, new NCILib.PlainText(server, $"Hallo i bin a test-Message N° {i++}"));
                Thread.Sleep(333);
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            #region ========= SETTING UP THE SERVER =========

            // Define the tcp-port on which the communication should take place
            int tcpServerPort = 2225;

            // Create a instance of the server
            NetComServer server = new NetComServer(tcpServerPort);

            // Set the wanted Debug-Output
            // Pre-Defined debug-outputs can be found
            // in the DebugOutput-Class
            server.SetDebugOutput(DebugOutput.ToConsole);

            // Set the authentication-method.
            // Authentication-Methods can be customly created, as long as
            // they accept a username [string] and a password [string] and
            // return true or false wether the authentication / login was successfull or not
            server.SetAuthenticationTool(AuthenticationTools.DebugAuth);

            // Start the server and all its background-processes.
            server.Start();

            #endregion

            #region ========= COMMUNICATE WITH CLIENTS =========

            // Create the instruction you want to send. General purpose-instructions are defined in the
            // InstructionLibraryEssentials-class. Additional Instructions are defined in the
            // InstructionLibraryExtensions-class. Custom instructions can be created as shown in the
            // "DemoNetComCustomInstructions"-Project

            #region ------ (1.) Send a message to a single connected client ------

            // Connected clients can be selected using the server.ConnectedClients-Property.

            var instruction1 = new InstructionLibraryEssentials.SimpleMessageBox
                                   (server, server.ConnectedClients[0], "Hello world.");

            // As soon as server.Send(...) gets called, the instruction is queued for sending and gets
            // sent out as soon as the instruction-preprocessing is done.
            server.Send(instruction1);

            #endregion

            #region ------ (2.) Send a message to all connected clients (Broadcast) ------

            // When creating a broadcast-message, the receiver-argument gets set to 'null'

            var instruction2 = new InstructionLibraryEssentials.SimpleMessageBox
                                   (server, null, "Hello world.");

            server.Broadcast(instruction2);

            #endregion

            #region ------ (3.) Send a message to a list of clients ------

            // When creating a list-message, the receiver-argument gets set to 'null'

            var instruction3 = new InstructionLibraryEssentials.SimpleMessageBox
                                   (server, null, "Hello world.");

            server.ListSend(instruction3, server.ConnectedClients[0], server.ConnectedClients["SampleUser01"]);

            #endregion

            #region ------ (4.) Send a message to a pre-defined group of clients ------

            // When creating a group-message, the receiver-argument gets set to 'null'

            var instruction4 = new InstructionLibraryEssentials.SimpleMessageBox
                                   (server, null, "Hello world.");

            server.GroupSend(instruction4, server.UserGroups["SampleUserGroup"]);

            #endregion

            #endregion
        }