我在这里浏览了论坛,这是我发现的最接近的问题:
如何(de)在WebSockets hybi 08+中构建数据框架?
不同之处在于我无法获得成功的握手.我假设在握手完成之后,框架不会发挥作用,这是正确的吗?
当Chrome方便地更新到使用HyBi 10 websocket协议(http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10)的版本14时,我即将发布概念验证.根据握手规范中的信息(http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10#section-5.2.2),我已经能够成功创建一个Sec-WebSocket - 接受键(基于他们的例子成功),但在客户端,socket.onopen函数永远不会触发.
上次我遇到了WebSocket协议握手的问题,这是一个用正确的字节终止握手的问题(或者我认为字符更准确?).我正在使用PHP进行当前的实现,这意味着尝试解码Python或C#实现,到目前为止还没有成功.
以下是我在Chrome 14(适用于Windows)中运行的客户端Javascript:
var socket;
socket = new WebSocket(host);
socket.onopen = function(msg){
// process onopen
};
socket.onmessage = function(msg){
// process message
};
socket.close = function(msg){
// process close
};
Run Code Online (Sandbox Code Playgroud)
这是我的握手服务器端PHP代码:
function dohandshake($user,$buffer){
// getheaders and calcKey are confirmed working, can provide source if desired
list($resource,$host,$origin,$key,$version) = $this->getheaders($buffer);
$request = "HTTP/1.1 101 Switching Protocols\r\n" .
"Upgrade: WebSocket\r\n" .
"Connection: Upgrade\r\n" .
"Sec-WebSocket-Accept: " . $this->calcKey($key) . …Run Code Online (Sandbox Code Playgroud) 简短说明:我使用OO Javascript与函数声明,新关键字和原型方法(下面的示例).我需要一种方法来引用对象的每个方法中的"self"对象."这个"似乎只有在我直接调用方法时才有效,否则"this"似乎是指任何称为方法的东西.
更多细节:这是我的对象的简化版本.
function Peer(id) {
this.id = id;
this.pc = new RTCPeerConnection(SERVER);
this.pc.onevent1 = this.onEvent1;
this.pc.onevent2 = this.onEvent2;
}
Peer.prototype.doSomething = function() {
// create offer takes one param, a callback function
this.pc.createOffer(this.myCallback);
};
Peer.prototype.onEvent1 = function(evt) {
// here this refers to the RTCPeerConnection object, so this doesn't work
this.initSomething(evt.data);
};
Peer.prototype.myCallback = function(data) {
// here this refers to the window object, so this doesn't work
this.setSomething = data;
};
Peer.prototype.initSomething = function(data) {
// use data …Run Code Online (Sandbox Code Playgroud)