Ejemplo n.º 1
0
        public void PostInputData(HttpListenerContext context)
        {
            if (context.Request.HttpMethod != "POST")
            {
                context.Response.StatusCode = (int) HttpStatusCode.NotFound;
                _lastAnswer = null;
                return;
            }

            string data;
            using (var streamReader = new StreamReader(context.Request.InputStream))
            {
                data = streamReader.ReadToEnd();
            }
            context.Response.StatusCode = (int)HttpStatusCode.OK;
            Send(context);

            var adapter = new JsonIOAdapter(new IOAdapter());
            _lastAnswer = adapter.Convert(data);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            int port;
            var portStr = Console.ReadLine();
            if (!int.TryParse(portStr, out port))
                return;

            var settings = new HttpMessengerSettings()
            {
                Host = "http://127.0.0.1",
                Port = port
            };
            var httpMessenger = new HttpMessenger(settings);
            while (httpMessenger.SendGet("Ping").StatusCode != HttpStatusCode.OK)
            {
            }

            var response = httpMessenger.SendGet("GetInputData");
            var adapter = new JsonIOAdapter(new IOAdapter());
            var answer = adapter.Convert(response.Data);

            httpMessenger.SendPost("WriteAnswer", Encoding.UTF8.GetBytes(answer));
        }