Пример #1
0
        public async Task <object> Send(CrossSocket client, Request request, bool nowait)
        {
            int taskid = this.taskid++;

            if (nowait)
            {
                request.taskid = -1;
                this.taskid--;
            }
            else
            {
                request.taskid = taskid;
            }

            string content = JsonConvert.SerializeObject(request);

            byte[] data = Encoding.UTF8.GetBytes(content + "\n");
            await client.SendAsync(data);

            if (!nowait)
            {
                SocketStore store = GetStoreForSocket(client, true);
                store.tasks[taskid] = new TaskCompletionSource <object>();
                return(await store.tasks[taskid].Task);
            }
            return(null);
        }
Пример #2
0
        public async void SendAnswer(CrossSocket client, JObject command, object result)
        {
            Answer answer = new Answer();

            answer.taskid      = command.Value <int>("taskid");
            answer.result.data = ConvertArgument(result, client);
            string content = JsonConvert.SerializeObject(answer);

            //Console.WriteLine("sending: " + content);
            byte[] data = Encoding.UTF8.GetBytes(content + "\n");
            await client.SendAsync(data);
        }
Пример #3
0
        public async void SendAnswerError(CrossSocket client, JObject command, Exception error)
        {
            //Console.WriteLine(error.Message);
            Answer answer = new Answer();

            answer.taskid               = command.Value <int>("taskid");
            answer.result.error         = new Error();
            answer.result.error.message = error.Message;
            answer.result.error.stack   = error.Message + "\n" + error.StackTrace;
            answer.result.error.code    = error.GetType().FullName;

            string content = JsonConvert.SerializeObject(answer);

            byte[] data = Encoding.UTF8.GetBytes(content + "\n");
            await client.SendAsync(data);
        }