public void Redirect(string url) { try { byte[] bHeader = charEncoder.GetBytes(WriterUtils.CreateStringHeader("text/html", "300 Moved")); clientSocket.Send(bHeader); } catch (SocketException e) { logger.Error(e, "Send response error.."); } catch (Exception e) { logger.Fatal(e, "Send response unhandled error.."); throw; } finally { Interrupt(); } }
public void Redirect(string url) { try { byte[] bHeader = charEncoder.GetBytes(WriterUtils.CreateStringHeader("text/html", "300 Moved")); clientSocket.BeginSend(bHeader, 0, bHeader.Length, flags, ar => logger.Info("End async send (redirect)"), null); } catch (SocketException e) { logger.Error(e, "Send response error.."); } catch (Exception e) { logger.Fatal(e, "Send response unhandled error.."); throw; } finally { Interrupt(); } }
public void SendResponse(byte[] bContent, string responseCode, string contentType, Dictionary <string, string> cookies) { try { byte[] bHeader = charEncoder.GetBytes(WriterUtils.CreateStringHeader(contentType, responseCode, bContent.Length, cookies)); clientSocket.Send(bHeader); if (bContent.Length > 10240) { for (int i = 0; i < bContent.Length; i += 10240) { clientSocket.BeginSend(bContent.Skip(i).Take(10240).ToArray(), 0, bContent.Length, flags, ar => logger.Info("End async (responsing)"), null); } } else { clientSocket.BeginSend(bContent, 0, bContent.Length, flags, ar => logger.Info("End async (responsing)"), null); } } catch (SocketException e) { logger.Error(e, "Send response error.."); } catch (Exception e) { logger.Fatal(e, "Send response unhandled error.."); throw; } finally { Interrupt(); } }