public void initSocket(string host, int port, string token, getResponse r, socketDisconnected x)
        {
            // Connect to a remote device.
            try
            {
                socketClosed = x;
                del          = r;
                // Establish the remote endpoint for the socket.
                IPAddress  ipAddress = IPAddress.Parse(host);
                IPEndPoint remoteEP  = new IPEndPoint(ipAddress, port);

                // Create a TCP/IP socket.
                client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                // Connect to the remote endpoint.
                client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client);
                connectDone.WaitOne();

                // Send test data to the remote device.
                sendData(token);
                sendDone.WaitOne();

                // Receive the response from the remote device.
                Receive(client);
                receiveDone.WaitOne();
            }
            catch (Exception e)
            {
                string response = "{'response_type': 'auth','response': 'error','message' : '" + e.Message + "'}";
                del(response);
            }
        }
 public MainWindow()
 {
     InitializeComponent();
     socket       = new SocketHandler();
     receiveData  = new getResponse(dataReceived);
     sendReq      = new sendRequest(dataSend);
     showLogin    = new showLoginForm(showLoginFormWindow);
     socketStatus = new socketDisconnected(socketClosed);
 }
 //this method will be used to initialize a socket connection with server
 public void initSocket(string host, int port, string token, getResponse r, socketDisconnected x)
 {
     try
     {
         socketClosed = x;
         del          = r;
         socket       = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         socket.Connect(host, port);
         socket.Send(Encoding.ASCII.GetBytes(token));
         if (!worker.IsBusy)
         {
             worker.RunWorkerAsync();
         }
     }
     catch (SocketException e)
     {
         string response = "{'response_type': 'auth','response': 'error','message' : '" + e.Message + "'}";
         del(response);
     }
 }