public void close()
    {
        lock (lockThis) {
            if (!connected)
            {
                //Console.WriteLine("Trying to close, but not connected");
                return;
            }

            if (receiver.isRunning())
            {
                receiver.stopit();
            }

            sendCloseHandshake();

            closeStreams();

            eventHandler.OnClose();
        }
    }