private void ReadCallback(IAsyncResult ar) { // Retrieve the state object and the handler socket // from the asynchronous state object. var state = (StateObject)ar.AsyncState; var handler = state.workSocket; // Read data from the client socket. var bytesRead = handler.EndReceive(ar); if (bytesRead <= 0) { return; } // There might be more data, so store the data received so far. state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); // Check for end-of-file tag. If it is not there, read // more data. var content = state.sb.ToString(); if (content.IndexOf("\r\n", StringComparison.Ordinal) > -1) { var httpRequest = HttpRequest.Parse(content); { httpRequest.Server.DocumentRoot = _documentRoot.Replace("\\", "/"); if (!httpRequest.Server.DocumentRoot.EndsWith("/")) { httpRequest.Server.DocumentRoot += "/"; } httpRequest.Update(); } var resp = ProcessRequest(httpRequest); var byteContent = resp.GetComplete(OutupEncoding); // All the data has been read from the // client. Display it on the console. Console.WriteLine("Read {0} bytes from socket. \n Data : {1}", content.Length, content); // Echo the data back to the client. Send(handler, byteContent); } else { // Not all data received. Get more. handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, ReadCallback, state); } }
public MainWindow() { InitializeComponent(); { HttpRequest r = HttpRequest.Parse(HttpRequest.Example); } { ServerEngine e = ServerEngine.Instance; e.DocumentRoot = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cs2php", "webserver"); e.OnLog += e_OnLog; string[] args = Environment.GetCommandLineArgs(); foreach (var i in args.Skip(1)) { e.Load(i); } e.ListenPort = 11000; e.StartListening(); } }