static void ProcessTcpClient(TcpClient client)
{
try
{
SslStream stream = new SslStream(client.GetStream());
X509Certificate cert = new X509Certificate2(Certificate.CreateSelfSignCertificatePfx(
"CN=localhost", //host name
DateTime.Parse("2000-01-01"), //not valid before
DateTime.Parse("2099-01-01"), //not valid after
"mypassword"), "mypassword"); //password to encrypt key file)
stream.AuthenticateAsServer(cert);
byte[] requestBuffer = new byte[8192];
int read = stream.Read(requestBuffer, 0, 8192);
Array.Resize<byte>(ref requestBuffer, read);
string request = Encoding.UTF8.GetString(requestBuffer);
string requestedPath = request.Split('?')[0].Replace("GET ", "");
Console.WriteLine(client.GetHashCode() + " => " + requestedPath);
string response = "";
if (requestedPath == "/gamepad/shardlist")
{
}
else if (requestedPath == "/gamepad/lastshard")
{
}
string header = "HTTP/1.1 200 OK\r\nDate: Fri, 10 Feb 2012 09:19:00 GMT\r\nServer: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o\r\nContent-Length: " + response.Length + "\r\nContent-Type: text/html\r\n\r\n";
byte[] headerBytes = Encoding.UTF8.GetBytes(header);
byte[] responseBytes = Encoding.UTF8.GetBytes(response);
stream.Write(headerBytes);
stream.Flush();
stream.Write(responseBytes);
stream.Flush();
}
catch (Exception e)
{
Console.WriteLine("Exception occured!\nMessage: " + e.Message + "\n" + e.StackTrace);
}
}