Permalink
Browse files

Fixing websockets sample

  • Loading branch information...
1 parent 29d1d85 commit f9cbf91fff5bceb268f310b614196ebcc16b2f59 @loudej committed Jan 31, 2012
Showing with 9 additions and 15 deletions.
  1. +1 −1 src/sample/Sandbox/Program.cs
  2. +1 −1 src/sample/Sandbox/Sandbox.csproj
  3. +7 −13 src/sample/Sandbox/WebSockets.cs
@@ -181,7 +181,7 @@ private static void Configuration(IAppBuilder builder)
builder
.Use<AppDelegate,string,string>(SetResponseHeader, "Server", "Firefly")
.Use(ShowCalls)
- //.UseWebSockets("/socketserver", OnConnection)
+ .UseWebSockets("/socketserver", OnConnection)
.UseChunked()
.RunNancy();
}
@@ -73,7 +73,7 @@
<Compile Include="Utils\WriteStream.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <None Include="WebSockets.cs" />
+ <Compile Include="WebSockets.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\main\Firefly\Firefly.csproj">
@@ -62,10 +62,8 @@ public static AppDelegate Middleware(AppDelegate app, string path, Func<Action<i
Func<Action<int, ArraySegment<byte>>, Action<int, ArraySegment<byte>>> service)
{
return
- (next, error, complete) =>
+ (write, flush, end, cancel) =>
{
- var cancel = false;
-
Action<int, ArraySegment<byte>> outgoing =
(opcode, data) =>
{
@@ -74,14 +72,14 @@ public static AppDelegate Middleware(AppDelegate app, string path, Func<Action<i
bytes[0] = (byte)(0x80 | opcode);
bytes[1] = (byte)data.Count;
Array.Copy(data.Array, data.Offset, bytes, 2, data.Count);
- next(new ArraySegment<byte>(bytes, 0, bytes.Length), null);
+ write(new ArraySegment<byte>(bytes, 0, bytes.Length));
};
var incoming = service(outgoing);
var buffer = new ArraySegment<byte>(new byte[128], 0, 0);
requestBody.Invoke(
- (data, continuation) =>
+ data =>
{
buffer = Concat(buffer, data);
var header = 2;
@@ -147,17 +145,13 @@ public static AppDelegate Middleware(AppDelegate app, string path, Func<Action<i
incoming(opcode, messageBody);
return false;
},
+ _ => false,
ex =>
{
- //Console.WriteLine(path + " error");
- },
- () =>
- {
Console.WriteLine("complete");
- complete();
- });
-
- return () => cancel = true;
+ end(ex);
+ },
+ cancel);
};
}

0 comments on commit f9cbf91

Please sign in to comment.