Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- System.Net.Sockets.TcpListener listener = new(System.Net.IPAddress.Any, 8080);
- listener.Start();
- while (true)
- {
- try
- {
- await Task.Run(async () =>
- {
- using System.Net.Sockets.TcpClient client = listener.AcceptTcpClient();
- TextReader tr = new StreamReader(client.GetStream());
- string requestLine = tr.ReadLine().Split(' ').Skip(1).Take(1).Single();
- if (requestLine.EndsWith('/'))
- requestLine += "index.html";
- TextWriter tw = new StreamWriter(client.GetStream());
- await tw.WriteLineAsync("HTTP/1.1 200 OK");
- await tw.WriteLineAsync();
- await tw.WriteLineAsync();
- byte[] responseContent = File.ReadAllBytes("./wwwroot" + requestLine);
- BinaryWriter bw = new(client.GetStream());
- bw.Write(responseContent);
- await tw.FlushAsync();
- });
- }
- catch { }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement