Skip to content

Commit

Permalink
Add a C# version of the HTTP server for comparison.
Browse files Browse the repository at this point in the history
  • Loading branch information
panesofglass committed Oct 8, 2013
1 parent 1acf30f commit 6a9b9f5
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 131 deletions.
273 changes: 144 additions & 129 deletions Fracture.sln

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions samples/CSharpServer/App.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
85 changes: 85 additions & 0 deletions samples/CSharpServer/CSharpServer.csproj
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C04349E4-23EA-40D2-B252-EE1D75ADDE4A}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CSharpServer</RootNamespace>
<AssemblyName>CSharpServer</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\FSharp.Core.4.0.0\lib\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="HttpMachine">
<HintPath>..\..\packages\HttpMachine.0.9.0.0\lib\HttpMachine.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin">
<HintPath>..\..\packages\Microsoft.Owin.2.0.0-rc1\lib\net45\Microsoft.Owin.dll</HintPath>
</Reference>
<Reference Include="Owin">
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\fracture\Fracture.fsproj">
<Project>{020697d7-24a3-4ce4-a326-d2c7c204ffde}</Project>
<Name>Fracture</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\http\Fracture.Http.fsproj">
<Project>{13571762-e1c9-492a-9141-37aa0094759a}</Project>
<Name>Fracture.Http</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
59 changes: 59 additions & 0 deletions samples/CSharpServer/Program.cs
@@ -0,0 +1,59 @@
//----------------------------------------------------------------------------
//
// Copyright (c) 2011-2012 Dave Thomas (@7sharp9)
// Ryan Riley (@panesofglass)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Threading.Tasks;
using Fracture.Http;

namespace CSharpServer
{
class Program
{
static void Main(string[] args)
{
System.AppDomain.CurrentDomain.UnhandledException += Debug;

var server = new HttpServer(env =>
{
var context = new Microsoft.Owin.OwinContext(env);
var response = context.Response;
response.StatusCode = 200;
response.Headers.Add("Content-Type", new[] { "text/plain" });
response.Headers.Add("Content-Length", new[] { "13" });
response.Headers.Add("Server", new[] { "Fracture" });
response.Write("Hello, world!");
// Complete the Task.
return Task.FromResult<object>(null);
});

server.Start(6667);
Console.WriteLine("Running server on port 6667.");
Console.ReadLine();
server.Dispose();
}

static void Debug(object sender, UnhandledExceptionEventArgs x)
{
Console.WriteLine("{0}", x.ExceptionObject);
Console.ReadLine();
}
}
}
36 changes: 36 additions & 0 deletions samples/CSharpServer/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CSharpServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CSharpServer")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("faeda8e5-1cca-4107-8088-958581cb7c0a")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
7 changes: 7 additions & 0 deletions samples/CSharpServer/packages.config
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Core" version="4.0.0" targetFramework="net45" />
<package id="HttpMachine" version="0.9.0.0" targetFramework="net45" />
<package id="Microsoft.Owin" version="2.0.0-rc1" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
</packages>
4 changes: 2 additions & 2 deletions samples/TestServer/Program.fs
Expand Up @@ -26,7 +26,6 @@ let debug (x:UnhandledExceptionEventArgs) =
Console.ReadLine() |> ignore

System.AppDomain.CurrentDomain.UnhandledException |> Observable.add debug
let shortdate = DateTime.UtcNow.ToShortDateString

let server = new HttpServer (fun env -> async {
let context = Microsoft.Owin.OwinContext(env)
Expand All @@ -39,5 +38,6 @@ let server = new HttpServer (fun env -> async {
})

server.Start(6667)
printfn "Http Server started on port 6667"
Console.WriteLine "Http Server started on port 6667"
Console.ReadKey() |> ignore
server.Dispose()

0 comments on commit 6a9b9f5

Please sign in to comment.