Visto l’affluenza a questo post da una moltitudine di anglofoni ho deciso di tradurlo in inglese e postarlo:
Sometimes is very useful to have a simple Web Server that accepts GET requests, as you can see is a teaching example, is not complete or had the same performance like an apache server but is useful if you need a “pocket webserver”.
We start, as usual, creating the solution, a Console Application, and writing the using header:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Sockets;
using System.Net;
and the declaration in the main method:
String requestMessageLine;
String fileName;
byte[] ip = {127,0,0,1};
TcpListener tcpListener = new TcpListener(new IPAddress(ip),6789); //Create a new Socket on 6789 port
tcpListener.Start();
Console.WriteLine("Server Started");
Socket connectionSocket;
See the ip variable contains the server ip (we also could write down al the settings in an ini file) and the tcpListener that creates a socket on localhost (127.0.0.1) listening on 6789 port.
Leggi il seguito di questo post »