예제 #1
0
파일: Payload.cs 프로젝트: kahowu/polymics
 public static Payload makePayload()
 {
     Payload p = new Payload();
     p.path = new List<String>();
     p.payload = new Dictionary<String, Object>();
     p.request = "";
     p.sessionid = 0;
     p.identity = 0;
     p.sessionkey = "";
     return p;
 }
예제 #2
0
        private bool StopTalking()
        {
            audioCaller.Close();
            connector.ReceivedData -= CancelRequested;

            //Stop recording

            Payload p = new Payload();
            p.request = "cancel";
            p.sessionkey = client.SessionKey;
            p.sessionid = client.SessionID;
            p.path = ClassRequested.path.Concat(new String[] {"audio"}).ToList();
            Random rnd = new Random();
            p.identity = packetIdentity = rnd.Next(Int32.MaxValue);
            ResponsePayload r = new ResponsePayload();
            r.message = "Connection: timeout!";
            Task k = Task.Factory.StartNew(() => { r = connector.SendAndReceive(p); });
            k.Wait(5000);
            if (r.status == "success")
            {
                return true;
            }
            else
            {
                client.currentError = r.message;
                return false;
            }
        }
예제 #3
0
        public bool CancelRequest()
        {
            if (CurrentAsk == null) return false;
            CurrentAsk.stopListening();
            CurrentAsk = null;
            RaisePropertyChanged("CurrentAsk");

            //Send request to remove from queue here!

            Payload p = new Payload();
            p.request = "cancel";
            p.sessionkey = client.SessionKey;
            p.sessionid = client.SessionID;
            p.path = path.Concat(new String[] {"audio"}).ToList();
            Random rnd = new Random();
            p.identity = rnd.Next(Int32.MaxValue);
            ResponsePayload r = new ResponsePayload();
            r.message = "Connection: timeout!";
            connector.Send (p);

            return true;
        }
예제 #4
0
파일: Api.cs 프로젝트: kahowu/polymics
 //
 //
 //
 public void SendBlock(Payload payload)
 {
     String s = JsonConvert.SerializeObject(payload);
     byte[] sendbuf = Encoding.ASCII.GetBytes(s);
     if (sendbuf.Length > 4096) throw new Exception("Packet size too large!");
     Socket.Send(sendbuf, sendbuf.Length);
 }
예제 #5
0
파일: Api.cs 프로젝트: kahowu/polymics
        /* SendAndReceive(Payload p)
         * Blocks until response is received
         *
         * Has timeout of 10 second for identity = 0
         * Unlimited timeout for specific identity, please timeout the thread manually.
         * */
        public ResponsePayload SendAndReceive(Payload p)
        {
            if (p.identity != 0)
            {
                SendBlock(p);
                while (responseWaiter == null || responseWaiter.identity != p.identity)
                {

                }
                return responseWaiter;
            }
            else
            {
                SendBlock(p);
                return waitForPayload();
            }
        }
예제 #6
0
파일: Api.cs 프로젝트: kahowu/polymics
        /* SendAndForget neithers blocks the thread nor wait for response
         * The client also timeouts in 3 seconds.*/
        public void Send(Payload p)
        {
            Task tk = Task.Factory.StartNew(() =>
            {
                try
                {
                    SendBlock(p);
                }
                catch
                {

                }
            });
        }