Last active
August 29, 2015 14:16
-
-
Save slofurno/8161f5370f7d5f2b0e7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication2 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
HttpREsponse().Wait(); | |
} | |
static string template = "<div class='squarediv'>{{div}}</div>"; | |
static async Task HttpREsponse() | |
{ | |
var url = Console.ReadLine(); | |
var response = template.Replace("{{div}}", url); | |
Console.WriteLine(response); | |
await Task.Delay(2000); | |
Console.WriteLine(response); | |
await Task.Delay(2000); | |
Console.WriteLine(response); | |
await Task.Delay(2000); | |
Console.WriteLine(response); | |
await Task.Delay(2000); | |
Console.WriteLine(response); | |
await Task.Delay(2000); | |
Console.WriteLine(response); | |
await Task.Delay(2000); | |
Console.WriteLine(response); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
char buffer[1000]; | |
fgets(buffer, 1000, stdin); | |
printf("<div class='squarediv'>%s</div>",buffer); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Net; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static string masterpage = @"<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'> | |
<style> | |
html{ | |
font-size: 14px | |
} | |
body{ | |
font-family: 'Open Sans',sans-serif; | |
line-height: 1.5; | |
color: #4D4E53; | |
background-color:#FFF; | |
color: #4D4E53; | |
} | |
.nothing{ | |
font-family: 'Open San',sans-serif; | |
line-height: 25px; | |
letter-spacing: -0.03em; | |
font-family: 'Source Sans Pro','Lucida Grande',sans-serif; | |
font-weight: 400; | |
font-size: 16px; | |
background-color: #EAEFF2; | |
} | |
.squarediv{ | |
background-color:red; | |
display:inline-block; | |
margin:10px; | |
width:100px; | |
height:100px; | |
} | |
</style> | |
</head> | |
<body>"; | |
static void Main(string[] args) | |
{ | |
ServicePointManager.UseNagleAlgorithm = false; | |
ServicePointManager.DefaultConnectionLimit = int.MaxValue; | |
Console.WriteLine(ServicePointManager.UseNagleAlgorithm); | |
Console.WriteLine(ServicePointManager.DefaultConnectionLimit); | |
RunServer().Wait(); | |
Console.ReadKey(); | |
} | |
static async Task RunServer() | |
{ | |
var listen = new HttpListener(); | |
listen.Prefixes.Add("http://+:1234/"); | |
listen.Start(); | |
while (true) | |
{ | |
var context = await listen.GetContextAsync().ConfigureAwait(false); | |
HandleConnection(context); | |
} | |
} | |
static async Task HandleConnection(HttpListenerContext context) | |
{ | |
ProcessStartInfo startInfo = new ProcessStartInfo(); | |
startInfo.FileName = "test.exe"; | |
startInfo.RedirectStandardInput = true; | |
startInfo.RedirectStandardOutput = true; | |
startInfo.UseShellExecute = false; | |
var test = Process.Start(startInfo); | |
var reader = test.StandardOutput; | |
var writer = test.StandardInput; | |
HttpListenerRequest request = context.Request; | |
// Obtain a response object. | |
HttpListenerResponse response = context.Response; | |
response.ContentType = "text/html"; | |
var httpout = response.OutputStream; | |
var firstresponse = Encoding.UTF8.GetBytes(masterpage); | |
await httpout.WriteAsync(firstresponse, 0, firstresponse.Length).ConfigureAwait(false); | |
await httpout.FlushAsync().ConfigureAwait(false); | |
await writer.WriteLineAsync(request.RawUrl).ConfigureAwait(false); | |
string line; | |
while((line = await reader.ReadLineAsync().ConfigureAwait(false))!=null){ | |
var str = Encoding.UTF8.GetBytes(line); | |
await httpout.WriteAsync(str, 0, str.Length).ConfigureAwait(false); | |
await httpout.FlushAsync().ConfigureAwait(false); | |
} | |
response.Close(); | |
} | |
static async Task ReadOutPut() | |
{ | |
ProcessStartInfo startInfo = new ProcessStartInfo(); | |
startInfo.FileName = "test.exe"; | |
startInfo.RedirectStandardInput = true; | |
startInfo.RedirectStandardOutput = true; | |
startInfo.UseShellExecute = false; | |
var test = Process.Start(startInfo); | |
var reader = test.StandardOutput; | |
var writer = test.StandardInput; | |
string line = ""; | |
writer.WriteLine("hey"); | |
while((line = await reader.ReadLineAsync())!=null){ | |
Console.WriteLine(line); | |
writer.WriteLine("hey"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment