// send a message to the given peer
        // m = JSON object
        // to = either a string or a JSON object to build an address from
        public void send(JObject m, JToken to = null)
        {
            Debug.WriteLine("SympleSignaller:send: " + m + " " + to);

            if (!IsConnected())
            {
                throw new Exception("cannot send messages while offline"); // TODO: add to pending queue?
            }

            if (m.Type != JTokenType.Object)
            {
                throw new Exception("message must be an object");
            }

            if (m["type"].Type != JTokenType.String)
            {
                m["type"] = "message";
            }

            if (m["id"] == null)
            {
                m["id"] = Symple.randomString(8);
            }

            if (to != null)
            {
                m["to"] = to;
            }

            if (m["to"] != null && m["to"].Type == JTokenType.Object)
            {
                JObject mToObj = (JObject)m["to"];
                m["to"] = Symple.buildAddress(mToObj);
            }

            if (m["to"] != null && m["to"].Type != JTokenType.String)
            {
                throw new Exception("message 'to' attribute must be an address string");
            }

            m["from"] = buildAddress(_myPeerData);

            if (m["from"] == m["to"])
            {
                throw new Exception("message sender cannot match the recipient");
            }

            Messenger.Broadcast(SympleLog.LogTrace, "symple:client: sending" + m);

            _socket.Send(m);
        }
 private string buildAddress(PeerData pd)
 {
     return(Symple.buildAddress(peerDataToJObject(pd)));
 }