/// <summary> /// Metodo ReciveCallBack: Metodo en el cual el servidor recibe la seƱal del cliente, se genera el contenido para la respuesta /// y se envia /// </summary> /// <param name="ar"></param> private void ReciveCallback(IAsyncResult ar) { Socket client = (Socket)ar.AsyncState; int size = client.EndReceive(ar); Byte[] RecivedBytes = new Byte[size]; Array.Copy(buffer, RecivedBytes, size); String data = Encoding.ASCII.GetString(RecivedBytes); Program.AddLog(data); string response; HttpResponseMessage httpResponse; try { HttpRequestMessage request = new HttpRequestMessage(data); Program.AddLog(JsonConvert.SerializeObject(request)); //TODO: Interpretar URI, si existe cargar el HTML como string httpResponse = MessageConstructor.ResponseMessage(request.HTTPVersion, request.RequestURI, request.Method); response = httpResponse.GenerateHttpResponse(); Program.AddLog(JsonConvert.SerializeObject(httpResponse)); } catch (NotSupportedException ne) { httpResponse = MessageConstructor.ResponseMethodNotAllowedMessage("HTTP/1.1"); response = httpResponse.GenerateHttpResponse(); } byte[] responseBytes = Encoding.ASCII.GetBytes(response); client.BeginSend(responseBytes, 0, responseBytes.Length, SocketFlags.None, new AsyncCallback(SendCallback), client); }