2013-06-06 36 views
1

我使用dojo 1.8.3版本。尝试在服务器上使用带有node.js socket.io的dojox套接字。 客户端代码Dojox套接字例外与node.js socket.io

<!DOCTYPE HTML> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>Demo: Basic Programmatic Chart</title> 
     <link rel="stylesheet" href="style.css" media="screen"> 
     <link rel="stylesheet" href="../../../resources/style/demo.css" media="screen"> 
    </head> 
    <body> 
     <!-- create the chart --> 
     <div id="chartNode" style="width: 550px; height: 550px;"></div> 

     <!-- load dojo and provide config via data attribute --> 
     <!-- load dojo and provide config via data attribute --> 
     <script src="http://localhost/dojo-release-1.8.3/dojo/dojo.js"></script> 

<script> 
dojo.ready(function(){ 
require([ 
    "dojo/request", "dojox/socket" 
], function(request, Socket){ 
    var 
     args = {}, 
     ws = typeof WebSocket != "undefined", 
     url = ws ? "/socket.io/websocket" : "/socket.io/xhr-polling"; 

    var socket = new Socket(args = { 
     url:url, 
     headers:{ 
      "Content-Type":"application/x-www-urlencoded" 
     }, 
     transport: function(args, message){ 
      args.data = message; // use URL-encoding to send the message instead of a raw body 
      request.post(url, args); 
     } 
    }); 
    var sessionId; 
    socket.on("message", function(){ 
     if (!sessionId){ 
      sessionId = message; 
      url += '/' + sessionId; 
     }else if(message.substr(0, 3) == '~h~'){ 
      // a heartbeat 
     } 
    }); 
}); 
}); 
</script> 

当创建的WebSocket(使用的Chrome版本27.0.1453.94米),它抛出异常“遗漏的类型错误:无法调用未定义的dojo.js的方法‘createEvent’:15306” 调用堆栈:

on.emit dojo.js:15306 
Socket.replace socket.js:78 
target.(anonymous function).dispatcher dojo.js:17098 
on.emit dojo.js:15270 
on.emit dojo.js:15317 
fire socket.js:205 
connect 

请让我知道如何让它工作。

+0

你能在Chrome检查器中设置断点,并通过一些步骤走? –

+0

new Socket调用 来自dojox/socket.js的Socket.WebSocket函数 这调用了 dojo.connect 这是抛出异常。调用堆栈上面提供 – PankajM

+0

这个问题的一些答案? –

回答

相关问题