Exemple #1
0
        private async Task <bool> Connect()
        {
            mSkynet.addNewReqListener(clientId, newReqListener);
            Utils.Log("Event: callback added ClientID: " + clientId);
            bool   status;
            string requuid = Guid.NewGuid().ToString();

            Utils.Log("Event: Start connect, ReqId: " + requuid + ", ClientId: " + clientId);
            var res = await mSkynet.sendRequest(new ToxId(targetToxId), new ToxRequest
            {
                url        = "/connect",
                method     = "get",
                uuid       = requuid,
                fromNodeId = clientId,
                fromToxId  = mSkynet.tox.Id.ToString(),
                toToxId    = targetToxId,
                toNodeId   = "",
                content    = Encoding.UTF8.GetBytes(ip.ToString() + "\n" + port),
                time       = Utils.UnixTimeNow(),
            }, out status);

            if (res == null || Encoding.UTF8.GetString(res.content) == "failed")
            {
                mSkynet.removeNewReqListener(clientId);
                Utils.Log("Event: Connect failed, ReqId: " + requuid + ", ClientId: " + clientId);
                return(false);
            }
            Utils.Log("Event: Connect success, ReqId: " + requuid + ", ClientId: " + clientId);
            serverId = res.fromNodeId;
            return(true);
        }