//send message from server panel
 private void send2_Click(object sender, EventArgs e)
 {
     if (AsynchronousServer.clients.Count == 0)
     {
         showAlert("No client is connected to server");
     }
     else
     {
         String data = this.input2.Text;
         AsynchronousServer.Send(data, -1);
         this.input2.Text = "";
     }
 }
        public void instanceClient()
        {
            this.connected           = true;
            itemStatus.ImageLocation = "green.bmp"; //set connected image in clients list

            chatThread = new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                while (connected)
                {
                    try
                    {
                        int receivedBytes = client.Receive(bytes);
                        //get message from connected client in bytes buffer
                        if (receivedBytes == 0) //if not bytes received means client lost connection
                        {
                            AsynchronousServer.ServerSetControlPropertyThreadSafe(AsynchronousServer.console, "Text", AsynchronousServer.console.Text + "Client " + index + " (" + key + "): Lost connection" + "  (" + index + ")" + "\n");
                            client.Shutdown(SocketShutdown.Both);
                            client.Close();
                            connected = false;
                            itemStatus.ImageLocation = "red.bmp";//set disconnected image in clients list
                        }
                        else //put buffer bytes in string
                        {
                            response = Encoding.ASCII.GetString(bytes, 0, receivedBytes);
                            AsynchronousServer.ServerSetControlPropertyThreadSafe(AsynchronousServer.console, "Text", AsynchronousServer.console.Text + "Client " + index + " (" + key + "): " + response);
                            Console.WriteLine("Console height: " + AsynchronousServer.console.Size.Height);
                            AsynchronousServer.Send(response, index);
                        }
                    }
                    catch (System.Net.Sockets.SocketException e)
                    {
                        connected = false;
                        connected = false;
                        itemStatus.ImageLocation = "red.bmp";//set disconnected image in clients list
                    }
                    Thread.Sleep(500);
                }
            });

            chatThread.Start();
        }