<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Server-Client Chat Tutorial</title><link>https://sourceforge.net/p/wicked-networking/wiki/Server-Client%2520Chat%2520Tutorial/</link><description>Recent changes to Server-Client Chat Tutorial</description><atom:link href="https://sourceforge.net/p/wicked-networking/wiki/Server-Client%20Chat%20Tutorial/feed" rel="self"/><language>en</language><lastBuildDate>Fri, 29 Jan 2016 18:13:16 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/wicked-networking/wiki/Server-Client%20Chat%20Tutorial/feed" rel="self" type="application/rss+xml"/><item><title>Server-Client Chat Tutorial modified by Mohamed Mokhtar</title><link>https://sourceforge.net/p/wicked-networking/wiki/Server-Client%2520Chat%2520Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -72,7 +72,7 @@
 ~~~~
 The first parameter specifies the size of the buffer thais used to send data, I usually set that to 2040, the second parameter is the port number that the server will be working on, the port number specified on the client must be the same that's specified on the server, port numbers range from 0 to 65536, but only port numbers 0 to 1024 are reserved for privileged services, so use a number between 1024 and 65536, the next parameter is the backlog, the backlog is how much packets the server can receive at one frame, e.g. if the backlog is set to 1 and 2 packets are sent to the server at the same time, only one will be received, otherwise if the backlog is set to 5 and 5 packets is sent to the server at the same time it'll receive the 5, but not more than five at the same frame etc. ,the last parameter should be the object that we created to get the events.

-When ending the program, we should call the function `serverTCP.KILLServer();` to close the server, as long as the server program is still open, it'll call any event that happens as a function in our events object we just created, for a console application we will call `Console.Readline ()` to prevent the program from closing, that should be the code for now:
+When ending the program, we should call the function `serverTCP.KILLServer()` to close the server, as long as the server program is still open, it'll call any event that happens as a function in our events object we just created, for a console application we will call `Console.Readline ()` to prevent the program from closing, that should be the code for now:
 ~~~~
     class Server
     {
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohamed Mokhtar</dc:creator><pubDate>Fri, 29 Jan 2016 18:13:16 -0000</pubDate><guid>https://sourceforge.net83a3062d0748845bffae56f4621c9086a58b1179</guid></item><item><title>Server-Client Chat Tutorial modified by Mohamed Mokhtar</title><link>https://sourceforge.net/p/wicked-networking/wiki/Server-Client%2520Chat%2520Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -81,6 +81,81 @@
             ServerEvents events = new ServerEvents();
             WickedServerTCP serverTCP = new WickedServerTCP(2040, 12345, 5, events);

+            Console.WriteLine("Server Setup Done!");
+            Console.ReadLine();
+            serverTCP.KILLServer();
+        }
+    }
+
+    public class myEventsClass
+    {
+        public ServerEvents() { }
+
+        public void clientForceDisconnect(Socket socket)
+        {
+            //A client left without telling me!!
+        }
+
+        public void clientConnect(Socket socket)
+        {
+             //A client just connected...
+        }
+
+        public void recvPacket(string text, Socket socket)
+        {
+            //just received some text 
+        }
+    }
+~~~~
+
+As for a Console program, we'll use `Console.WriteLine ()` to post on the console every event, this should be the code now:
+~~~~
+    class Server
+    {
+        static void Main(string[] args)
+        {
+            ServerEvents events = new ServerEvents();
+            WickedServerTCP serverTCP = new WickedServerTCP(2040, 12345, 5, events);
+
+            Console.WriteLine("Server Setup Done!");
+            Console.ReadLine();
+            serverTCP.KILLServer();
+        }
+    }
+
+    public class myEventsClass
+    {
+        public ServerEvents() { }
+
+        public void clientForceDisconnect(Socket socket)
+        {
+            //A client left without telling me!!
+            Console.WriteLine("Client Forcefully disconnected");
+        }
+
+        public void clientConnect(Socket socket)
+        {
+             //A client just connected...
+             Console.WriteLine("Client connected");
+        }
+
+        public void recvPacket(string text, Socket socket)
+        {
+            //just received some text 
+            Console.WriteLine(text);
+        }
+    }
+~~~~
+
+As for a chat program, we want the server to resend every packet it receives to all clients that's not the one it received from, because it's already typed in the sender's console, we need another `WickedServerTCP` object on the `myEventsClass` class, so we made a public `WickedServerTCP` object on that class ,and we set it's value to the value of "serverTCP" object after initialising it, we use `serverTCP.getClients()`, we want the clients to be able to leave peacefully too, we're going to use the "#Exit#" keyword to make the client exit, so if the client sends "#Exit#" the server will disconnect it by calling `serverTCP.closeClientSocket (socket)`, the code should look like this though:
+~~~~
+    class Server
+    {
+        static void Main(string[] args)
+        {
+            ServerEvents events = new ServerEvents();
+            WickedServerTCP serverTCP = new WickedServerTCP(2040, 12345, 5, events);
+            
             events.serverTCP = serverTCP;
             Console.WriteLine("Server Setup Done!");
             Console.ReadLine();
@@ -90,83 +165,8 @@

     public class myEventsClass
     {
-        public ServerEvents() { }
-
-        public void clientForceDisconnect(Socket socket)
-        {
-            //A client left without telling me!!
-        }
-
-        public void clientConnect(Socket socket)
-        {
-             //A client just connected...
-        }
-
-        public void recvPacket(string text, Socket socket)
-        {
-            //just received some text 
-        }
-    }
-~~~~
-
-As for a Console program, we'll use `Console.WriteLine ()` to post on the console every event, this should be the code now:
-~~~~
-    class Server
-    {
-        static void Main(string[] args)
-        {
-            ServerEvents events = new ServerEvents();
-            WickedServerTCP serverTCP = new WickedServerTCP(2040, 12345, 5, events);
-
-            events.serverTCP = serverTCP;
-            Console.WriteLine("Server Setup Done!");
-            Console.ReadLine();
-            serverTCP.KILLServer();
-        }
-    }
-
-    public class myEventsClass
-    {
-        public ServerEvents() { }
-
-        public void clientForceDisconnect(Socket socket)
-        {
-            //A client left without telling me!!
-            Console.WriteLine("Client Forcefully disconnected");
-        }
-
-        public void clientConnect(Socket socket)
-        {
-             //A client just connected...
-             Console.WriteLine("Client connected");
-        }
-
-        public void recvPacket(string text, Socket socket)
-        {
-            //just received some text 
-            Console.WriteLine(text);
-        }
-    }
-~~~~
-
-As for a chat program, we want the server to resend every packet it receives to all clients that's not the one it received from, because it's already typed in the sender's console, we need another `WickedServerTCP` object on the `myEventsClass` class, so we made a public `WickedServerTCP` object on that class ,and we set it's value after initialising "serverTCP" in the main class, then we set it's , we use `serverTCP.getClients()`, we want the clients to be able to leave peacefully too, we're going to use the "#Exit#" keyword to make the client exit, so if the client sends "#Exit#" the server will disconnect it, the code should look like this though:
-~~~~
-    class Server
-    {
-        static void Main(string[] args)
-        {
-            ServerEvents events = new ServerEvents();
-            WickedServerTCP serverTCP = new WickedServerTCP(2040, 12345, 5, events);
-
-            events.serverTCP = serverTCP;
-            Console.WriteLine("Server Setup Done!");
-            Console.ReadLine();
-            serverTCP.KILLServer();
-        }
-    }
-
-    public class myEventsClass
-    {
+        public WickedServerTCP serverTCP;
+    
         public ServerEvents() { }

         public void clientForceDisconnect(Socket socket)
@@ -203,3 +203,79 @@
         }
     }
 ~~~~
+
+Now we have the server done!!! for the client we'll make another public class, this class must have a public function named "recvPacket", and having only one parameter with type string, this is called when the client receives a packet from the server, as for a chat program and a console application, we'll use `Console.WriteLine(text)` to print any received messages, that class should look like this then:
+~~~~
+    public class myClientEvents
+    {
+        public void recvPacket(string text)
+        {
+            Console.WriteLine(text);
+        }
+    }
+~~~~
+
+At the beggining of the program we want to create a "myClientEvents" object to detect events, then make and construct a "WickedClientTCP" object, the first parameter is the ipAddress that I should connect to, this should be set to loopBack as for testing purposes, as LoopBack works in the localhost, when you're ready to go live, the server ip must be the public IP of the computer, add your IP as a parameter by using `new IPAddress("192.168.1.1")` and replacing "192.168.1.1" with your public IP, know your public IP from [HERE](http://whatismyipaddress.com/), the second parameter is the port number, as I said before the port specifies the program on your computer, this has to be the same as in the client, to go live you have to do port forwarding, learn how to port forward from [HERE](http://www.pcworld.com/article/244314/how_to_forward_ports_on_your_router.html), the third and last parameter is the events object we just created to detect events, that's what it's going to look like:
+~~~~
+ClientEvents events = new ClientEvents();
+            WickedClientTCP clientTCP = new WickedClientTCP (IPAddress.Loopback, 12345, events);
+~~~~
+
+The overall code should look like this:
+~~~~
+    class Client
+    {
+        static void Main(string[] args)
+        {
+            ClientEvents events = new ClientEvents();
+            WickedClientTCP clientTCP = new WickedClientTCP (IPAddress.Loopback, 12345, events);
+        }
+    }
+
+    public class ClientEvents
+    {
+        public void recvPacket(string text)
+        {
+            Console.WriteLine(text);
+        }
+    }
+~~~~
+
+Then we want the client to be able to send messages, we'll do this by making a boolean and set it to false, and make a while loop that loops if this boolean is set to false, in the loop we'll use `Console.Readline()` to detect the string typed by the user and send it to the server, if this string is set to "#Exit#" the boolean will be set true and the loop will exit, because the server will disconnect the client, after the loop has ended we call `clientTCP.stopListen()` to stop listening for packets, the overall code should look like that:
+~~~~
+    class Client
+    {
+        static void Main(string[] args)
+        {
+            ClientEvents events = new ClientEvents();
+            WickedClientTCP clientTCP = new WickedClientTCP (IPAddress.Loopback, 12345, events);
+
+            Console.WriteLine("Enter your message, enter '#Exit#' to exit:");
+
+            bool exit = false;
+
+            while (exit == false)
+            {
+                string mes = Console.ReadLine();
+
+                if (mes == "#Exit#")
+                {
+                    exit = true;
+                }
+                clientTCP.SendString(mes);
+            }
+            clientTCP.stopListen();
+        }
+    }
+
+    public class ClientEvents
+    {
+        public void recvPacket(string text)
+        {
+            Console.WriteLine(text);
+        }
+    }
+~~~~
+
+This way we finished the chat client and the chat server, you can download the source code of this program from [HERE](https://sourceforge.net/projects/wicked-networking/files/Chat-Example/) and build it, thanks for your time!!
+SHARE if you like it!!
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohamed Mokhtar</dc:creator><pubDate>Fri, 29 Jan 2016 18:11:32 -0000</pubDate><guid>https://sourceforge.net15714c6076f3c55b47abe5f4037ec5058fb7dca7</guid></item><item><title>Server-Client Chat Tutorial modified by Mohamed Mokhtar</title><link>https://sourceforge.net/p/wicked-networking/wiki/Server-Client%2520Chat%2520Tutorial/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;strong&gt;Welcome&lt;/strong&gt;&lt;br/&gt;
Hey guys, in this tutorial I'll be teaching u how to make a Chat program with a Server-Client Architecture, At first, u need to download the "WickedNetworking.dll" file from &lt;a class="" href="https://sourceforge.net/projects/wicked-networking/files/"&gt;HERE&lt;/a&gt; and add it to the References folder i ur project.&lt;/p&gt;
&lt;p&gt;Once ur done, I must know that this WickedNetworking is a simplified version of Winsock, WickedNetworking uses TCP as a protocol.&lt;/p&gt;
&lt;p&gt;Now for the fun!! Before anything type:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;using System.Net.Sockets;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then to make a server u must create a class to receive the events that gets called on the Server, &lt;br/&gt;
this class must be public, and must have 3 public functions, the first must be named "clientForceDisconnect" and have only one parameter with type "Socket", this function gets called when a client gets disconnected from the server without asking to, like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;public void clientForceDisconnect(Socket mySocketName)
{
        //A client left without telling me!!
}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Next function gets called when a client connects, this function must have a name of "clientConnect" and have only one parameter which is of type "Socket", like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;public void clientConnect(Socket socket)
{
        //A client just connected...
}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The third and last and the most important function gets called when the server receives a packet, a packet is an object containing some text, this function must have only two parameters, the first must be with type string, and the second must be with type Socket, this function must have a name of "recvPacket" like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;public void recvPacket(string text, Socket socket)
{
        //just received some text 
}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now the class should be done and ready to use, it should be like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    public class myEventsClass
    {
        public ServerEvents() { }

        public void clientForceDisconnect(Socket socket)
        {
            //A client left without telling me!!
        }

        public void clientConnect(Socket socket)
        {
             //A client just connected...
        }

        public void recvPacket(string text, Socket socket)
        {
            //just received some text 
        }
    }
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now, lets go to the code of our Server, before everything we wanna import this too:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;using System.Net.Sockets;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then create an object of the class we just created to receive the events:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;myEventsClass myEvents = new MyEventsClass();
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then construct a WickedServerTCP object:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;WickedServerTCP serverTCP = new WickedServerTCP(2040, 12345, 5, myEvents);
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The first parameter specifies the size of the buffer thais used to send data, I usually set that to 2040, the second parameter is the port number that the server will be working on, the port number specified on the client must be the same that's specified on the server, port numbers range from 0 to 65536, but only port numbers 0 to 1024 are reserved for privileged services, so use a number between 1024 and 65536, the next parameter is the backlog, the backlog is how much packets the server can receive at one frame, e.g. if the backlog is set to 1 and 2 packets are sent to the server at the same time, only one will be received, otherwise if the backlog is set to 5 and 5 packets is sent to the server at the same time it'll receive the 5, but not more than five at the same frame etc. ,the last parameter should be the object that we created to get the events.&lt;/p&gt;
&lt;p&gt;When ending the program, we should call the function &lt;code&gt;serverTCP.KILLServer();&lt;/code&gt; to close the server, as long as the server program is still open, it'll call any event that happens as a function in our events object we just created, for a console application we will call &lt;code&gt;Console.Readline ()&lt;/code&gt; to prevent the program from closing, that should be the code for now:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="n"&gt;Server&lt;/span&gt;
    {
        &lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;Main&lt;/span&gt;(&lt;span class="n"&gt;string&lt;/span&gt;[] &lt;span class="n"&gt;args&lt;/span&gt;)
        {
            &lt;span class="n"&gt;ServerEvents&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt; = &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="n"&gt;ServerEvents&lt;/span&gt;();
            &lt;span class="n"&gt;WickedServerTCP&lt;/span&gt; &lt;span class="n"&gt;serverTCP&lt;/span&gt; = &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="n"&gt;WickedServerTCP&lt;/span&gt;(&lt;span class="mi"&gt;2040&lt;/span&gt;, &lt;span class="mi"&gt;12345&lt;/span&gt;, &lt;span class="mi"&gt;5&lt;/span&gt;, &lt;span class="n"&gt;events&lt;/span&gt;);

            &lt;span class="n"&gt;events&lt;/span&gt;.&lt;span class="n"&gt;serverTCP&lt;/span&gt; = &lt;span class="n"&gt;serverTCP&lt;/span&gt;;
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="s"&gt;"Server Setup Done!"&lt;/span&gt;);
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;ReadLine&lt;/span&gt;();
            &lt;span class="n"&gt;serverTCP&lt;/span&gt;.&lt;span class="n"&gt;KILLServer&lt;/span&gt;();
        }
    }

    &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="n"&gt;myEventsClass&lt;/span&gt;
    {
        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;ServerEvents&lt;/span&gt;() { }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;clientForceDisconnect&lt;/span&gt;(&lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
            //&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="n"&gt;without&lt;/span&gt; &lt;span class="n"&gt;telling&lt;/span&gt; &lt;span class="n"&gt;me&lt;/span&gt;!!
        }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;clientConnect&lt;/span&gt;(&lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
             //&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="n"&gt;just&lt;/span&gt; &lt;span class="n"&gt;connected&lt;/span&gt;...
        }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;recvPacket&lt;/span&gt;(&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;, &lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
            //&lt;span class="n"&gt;just&lt;/span&gt; &lt;span class="n"&gt;received&lt;/span&gt; &lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; 
        }
    }
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;As for a Console program, we'll use &lt;code&gt;Console.WriteLine ()&lt;/code&gt; to post on the console every event, this should be the code now:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="n"&gt;Server&lt;/span&gt;
    {
        &lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;Main&lt;/span&gt;(&lt;span class="n"&gt;string&lt;/span&gt;[] &lt;span class="n"&gt;args&lt;/span&gt;)
        {
            &lt;span class="n"&gt;ServerEvents&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt; = &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="n"&gt;ServerEvents&lt;/span&gt;();
            &lt;span class="n"&gt;WickedServerTCP&lt;/span&gt; &lt;span class="n"&gt;serverTCP&lt;/span&gt; = &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="n"&gt;WickedServerTCP&lt;/span&gt;(&lt;span class="mi"&gt;2040&lt;/span&gt;, &lt;span class="mi"&gt;12345&lt;/span&gt;, &lt;span class="mi"&gt;5&lt;/span&gt;, &lt;span class="n"&gt;events&lt;/span&gt;);

            &lt;span class="n"&gt;events&lt;/span&gt;.&lt;span class="n"&gt;serverTCP&lt;/span&gt; = &lt;span class="n"&gt;serverTCP&lt;/span&gt;;
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="s"&gt;"Server Setup Done!"&lt;/span&gt;);
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;ReadLine&lt;/span&gt;();
            &lt;span class="n"&gt;serverTCP&lt;/span&gt;.&lt;span class="n"&gt;KILLServer&lt;/span&gt;();
        }
    }

    &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="n"&gt;myEventsClass&lt;/span&gt;
    {
        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;ServerEvents&lt;/span&gt;() { }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;clientForceDisconnect&lt;/span&gt;(&lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
            //&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="n"&gt;without&lt;/span&gt; &lt;span class="n"&gt;telling&lt;/span&gt; &lt;span class="n"&gt;me&lt;/span&gt;!!
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="s"&gt;"Client Forcefully disconnected"&lt;/span&gt;);
        }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;clientConnect&lt;/span&gt;(&lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
             //&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="n"&gt;just&lt;/span&gt; &lt;span class="n"&gt;connected&lt;/span&gt;...
             &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="s"&gt;"Client connected"&lt;/span&gt;);
        }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;recvPacket&lt;/span&gt;(&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;, &lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
            //&lt;span class="n"&gt;just&lt;/span&gt; &lt;span class="n"&gt;received&lt;/span&gt; &lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; 
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="n"&gt;text&lt;/span&gt;);
        }
    }
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;As for a chat program, we want the server to resend every packet it receives to all clients that's not the one it received from, because it's already typed in the sender's console, we need another &lt;code&gt;WickedServerTCP&lt;/code&gt; object on the &lt;code&gt;myEventsClass&lt;/code&gt; class, so we made a public &lt;code&gt;WickedServerTCP&lt;/code&gt; object on that class ,and we set it's value after initialising "serverTCP" in the main class, then we set it's , we use &lt;code&gt;serverTCP.getClients()&lt;/code&gt;, we want the clients to be able to leave peacefully too, we're going to use the "#Exit#" keyword to make the client exit, so if the client sends "#Exit#" the server will disconnect it, the code should look like this though:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="n"&gt;Server&lt;/span&gt;
    {
        &lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;Main&lt;/span&gt;(&lt;span class="n"&gt;string&lt;/span&gt;[] &lt;span class="n"&gt;args&lt;/span&gt;)
        {
            &lt;span class="n"&gt;ServerEvents&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt; = &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="n"&gt;ServerEvents&lt;/span&gt;();
            &lt;span class="n"&gt;WickedServerTCP&lt;/span&gt; &lt;span class="n"&gt;serverTCP&lt;/span&gt; = &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="n"&gt;WickedServerTCP&lt;/span&gt;(&lt;span class="mi"&gt;2040&lt;/span&gt;, &lt;span class="mi"&gt;12345&lt;/span&gt;, &lt;span class="mi"&gt;5&lt;/span&gt;, &lt;span class="n"&gt;events&lt;/span&gt;);

            &lt;span class="n"&gt;events&lt;/span&gt;.&lt;span class="n"&gt;serverTCP&lt;/span&gt; = &lt;span class="n"&gt;serverTCP&lt;/span&gt;;
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="s"&gt;"Server Setup Done!"&lt;/span&gt;);
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;ReadLine&lt;/span&gt;();
            &lt;span class="n"&gt;serverTCP&lt;/span&gt;.&lt;span class="n"&gt;KILLServer&lt;/span&gt;();
        }
    }

    &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="n"&gt;myEventsClass&lt;/span&gt;
    {
        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;ServerEvents&lt;/span&gt;() { }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;clientForceDisconnect&lt;/span&gt;(&lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
            //&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="n"&gt;without&lt;/span&gt; &lt;span class="n"&gt;telling&lt;/span&gt; &lt;span class="n"&gt;me&lt;/span&gt;!!
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="s"&gt;"Client Forcefully disconnected"&lt;/span&gt;);
        }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;clientConnect&lt;/span&gt;(&lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
             //&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="n"&gt;just&lt;/span&gt; &lt;span class="n"&gt;connected&lt;/span&gt;...
             &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="s"&gt;"Client connected"&lt;/span&gt;);
        }

        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;void&lt;/span&gt; &lt;span class="n"&gt;recvPacket&lt;/span&gt;(&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;, &lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;)
        {
            //&lt;span class="n"&gt;just&lt;/span&gt; &lt;span class="n"&gt;received&lt;/span&gt; &lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; 
            &lt;span class="n"&gt;Console&lt;/span&gt;.&lt;span class="n"&gt;WriteLine&lt;/span&gt;(&lt;span class="n"&gt;text&lt;/span&gt;);

            &lt;span class="k"&gt;if&lt;/span&gt; (&lt;span class="n"&gt;text&lt;/span&gt; != &lt;span class="s"&gt;"#Exit#"&lt;/span&gt;)
            {
                &lt;span class="n"&gt;foreach&lt;/span&gt; (&lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;S&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;serverTCP&lt;/span&gt;.&lt;span class="n"&gt;getClients&lt;/span&gt;())
                {
                    &lt;span class="k"&gt;if&lt;/span&gt; (&lt;span class="n"&gt;S&lt;/span&gt; != &lt;span class="n"&gt;socket&lt;/span&gt;)
                    {
                        &lt;span class="n"&gt;serverTCP&lt;/span&gt;.&lt;span class="n"&gt;SendString&lt;/span&gt;(&lt;span class="n"&gt;text&lt;/span&gt;, &lt;span class="n"&gt;S&lt;/span&gt;);
                    }
                }
            }
            &lt;span class="k"&gt;else&lt;/span&gt;
            {
                &lt;span class="n"&gt;serverTCP&lt;/span&gt;.&lt;span class="n"&gt;closeClientSocket&lt;/span&gt; (&lt;span class="n"&gt;socket&lt;/span&gt;);
            }
        }
    }
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohamed Mokhtar</dc:creator><pubDate>Fri, 29 Jan 2016 17:22:40 -0000</pubDate><guid>https://sourceforge.net4c582edbc6cbf097ed87c1ce0e794e73f3134714</guid></item></channel></rss>