I’ve been trying to get the echo server sample in Fleck (C# websocket server implementation) working with web-socket-js (flash powered websockets for legacy browsers), and have been running into problems.
The first problem I ran into was getting the Client Access Policy uploading from port 843. I gave up and just added some quick and dirty code to Fleck’s WebSocketConnection read method…
if (body.StartsWith("<policy-file-request/>"))
{
FleckLog.Debug("Reveived Flash Policy File Request");
var policyFile = @"<?xml version=""1.0""?><!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd""><cross-domain-policy><allow-access-from domain=""*"" to-ports=""*""/></cross-domain-policy>";
byte[] bytes = new System.Text.UTF8Encoding().GetBytes(policyFile);
Socket.Stream.Write(bytes, 0, bytes.Length);
Socket.Stream.WriteByte(0);
Socket.Stream.WriteByte(13);
FleckLog.Debug("Flash Policy File Sent");
return;
}
Now it just seems to hang. Here are the logs…
web-socket-js logs:
LOG: [FLASH]:[WebSocket] debug enabled
LOG: [FLASH]:[WebSocket] policy file: xmlsocket://localhost:843
LOG: [FLASH]:[WebSocket] connected
LOG: [FLASH]:[WebSocket] request header:
GET / HTTP/1.1
Host: localhost:8181
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: IVcOUW1sZkUxMGFNJ257dA==
Origin: http://localhost:6976
Sec-WebSocket-Version: 13
Cookie:
From the Fleck echo server I’m getting this…
12/11/2012 2:38:37 PM [Info] Server started at ws://localhost:8181
12/11/2012 2:38:43 PM [Debug] Client Connected
12/11/2012 2:38:43 PM [Debug] Received:
12/11/2012 2:38:43 PM [Debug] 23 bytes read
12/11/2012 2:38:43 PM [Debug] Received: <policy-file-request/>
12/11/2012 2:38:43 PM [Debug] Reveived Flash Policy File Request
12/11/2012 2:38:43 PM [Debug] Flash Policy File Sent
12/11/2012 2:38:43 PM [Debug] Client Connected
12/11/2012 2:38:43 PM [Debug] Received:
12/11/2012 2:38:43 PM [Debug] 194 bytes read
12/11/2012 2:38:43 PM [Debug] Received: GET / HTTP/1.1
Host: localhost:8181
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dgNDXk5mfWYPbVlnImYDEA==
Origin: http://localhost:6976
Sec-WebSocket-Version: 13
Cookie:
Has anyone gotten these two libraries to get along? I’m using IE 9.0, Flash 11.5.502.110, and .NET 4.0. This sample works perfectly with web-socket-ruby/samples/echo_server.rb w/ IE 9.0, Flash 11.5.502.110, and the Fleck sample echo server works perfectly with Firefox/Chrome/etc…
Found it. The Fleck regular expression used to parse the headers in the Web Socket Request were too strict and expected a newline which the flash client didn’t provide.