Jump to content

websocket server

- - - - -

  • Please log in to reply
2 replies to this topic

#1
h_istvan33

h_istvan33

    Newbie

  • Members
  • Pip
  • 1 posts
Hi!

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


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,720 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
So what exactly is your problem? Websockets won't be supported in Firefox until version 6, apparently; I'm not sure about others. Chrome is just ahead, that's all.
sudo rm -rf /

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
You've to understand that it is an early draft:
http://dev.w3.org/html5/websockets/

The layout engines will implement these, Webkit based browsers (i.e. Safari, Chrome) support this better than others (Trident, Gecko)
http://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28HTML_5%29#Related_specifications

Feel free to follow individual mail lists or road maps, or keep an eye on that page to view the progress of implementation.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users