public void connect()
    {
        try {
            if (connected)
            {
                throw new SocketIoClientException("already connected");
            }

            socket = createSocket();
            stream = socket.GetStream();

            input = new StreamReader(stream);
            byte[] bytes = handshake.getHandshake();
            stream.Write(bytes, 0, bytes.Length);
            stream.Flush();

            bool          handshakeComplete = false;
            List <string> handshakeLines    = new List <string>();
            string        line;

            while (!handshakeComplete)
            {
                line = input.ReadLine().Trim();
                if (line.Length > 0)
                {
                    handshakeLines.Add(line);
                }
                else
                {
                    handshakeComplete = true;
                }
            }

            char[] response = new char[16];
            input.ReadBlock(response, 0, response.Length);

            handshake.verifyServerStatusLine(handshakeLines[0]);

            /* Verifying handshake fails... */
            //handshake.verifyServerResponse(response);

            handshakeLines.RemoveAt(0);

            Dictionary <string, string> headers = new Dictionary <string, string>();
            foreach (string l in handshakeLines)
            {
                string[] keyValue = l.Split(new char[] { ':' }, 2);
                headers.Add(keyValue[0].Trim(), keyValue[1].Trim());
            }

            handshake.verifyServerHandshakeHeaders(headers);
            receiver  = new SocketIoClientReceiver(this);
            connected = true;
            eventHandler.OnOpen();
            (new Thread(receiver.run)).Start();
        } catch (SocketIoClientException wse) {
            throw wse;
        } catch (IOException ioe) {
            throw new SocketIoClientException("error while connecting: " + ioe.StackTrace, ioe);
        }
    }