I made a websocket server, but It only works in chrome. I tried to use opera11, FireFox4, Safari5, but with these it dont works. (I re-enabled websockets in FF and Opera) I can connect, but after I sended back the datas, the webbrowser closed the connection (with google chrome, it works)
Try it out here: http://sockettest.fw.hu
In C# I respond to the header with this code:
string[] headlines = theheader.Split(Convert.ToChar("\n"));
string key1 = "";
string key2 = "";
string origin0 = "";
var key = new byte[8];
foreach (string sor in headlines)
{
if (sor.Length > 20)
{
if (sor.Substring(0, 20) == "Sec-WebSocket-Key1: ")
{
key1 = sor.Substring(20);
}
else if (sor.Substring(0, 20) == "Sec-WebSocket-Key2: ")
{
key2 = sor.Substring(20);
}
else if (sor.Substring(0, 8) == "Origin: ")
{
origin0 = sor.Substring(8);
}
}
else if (sor.Length <= 8)
{
key = Encoding.Default.GetBytes(sor);
}
}
var numbersKey1 = Convert.ToInt64(string.Join(null, Regex.Split(key1, "[^\d]")));
var numbersKey2 = Convert.ToInt64(string.Join(null, Regex.Split(key2, "[^\d]")));
var numberSpaces1 = CountSpaces(key1);
var numberSpaces2 = CountSpaces(key2);
var part1 = (int)(numbersKey1 / numberSpaces1);
var part2 = (int)(numbersKey2 / numberSpaces2);
var result = new List<byte>();
result.AddRange(GetBigEndianBytes(part1));
result.AddRange(GetBigEndianBytes(part2));
result.AddRange(key);
using (var md5 = MD5.Create())
{
string handshake = Encoding.Default.GetString(md5.ComputeHash(result.ToArray()));
handshake = "HTTP/1.1 101 WebSocket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nSec-WebSocket-Origin: " + origin0 + "\r\nSec-WebSocket-Location: ws://" + netip + ":" + port.ToString() + "/\r\nSec-WebSocket-Protocol: *\r\n\r\n" + handshake;
}
Edited by dargueta, 07 August 2011 - 12:50 PM.
Reformatted code


Sign In
Create Account

Back to top









