2

我正在关注socket.io的示例程序nodejs-drawing-game(http://tutorialzine.com/2012/08/nodejs-drawing-game/),使用railwayjs框架创建一个新副本(http:// /railwayjs.com/)。顺便说一下,我的开发环境是win7的node.js版。

我可以在本地电脑上运行 nodejs-drawing-game 本身,但是当我将它作为 wailwayjs 的模块运行时,我没有运气。我是 node.js 的新手,railwayjs ......任何人都可以帮助我克服这个卡住?任何帮助表示赞赏。

■ 项目目录:

+ yeahjs
+++ app / controllers
----- draw_controller.js
+++ app / views / draw
----- index.ejs   // see code as below
+++ node_modules
----- socket.io
----- socket.io-client    
+++ public
+++++ images
+++++ javascripts
----- script.js // the same as you can see on http://tutorialzine.com/2012/08/nodejs-drawing-game/
+++++ stylesheets

■ draw_controller.js

load('application');
action(function index() {   
    draw_app.init(); 
    render({
        title: "draw#index"
    });
});

var draw_app = {
    init: function(){
        // Including libraries
        var io = require('socket.io').listen(app);

        // Delete this row if you want to see debug messages
        io.set('log level', 3);

        // Listen for incoming connections from clients
        io.sockets.on('connection', function (socket) {

            // Start listening for mouse move events
            socket.on('mousemove', function (data) {

                // This line sends the event (broadcasts it)
                // to everyone except the originating client.
                socket.broadcast.emit('moving', data);
            });
        });
    }
}

■ 索引.ejs

<!-- The stylesheets -->
<link rel="stylesheet" href="stylesheets/styles.css" />

<!--[if lt IE 9]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<div id="cursors">
    <!-- The mouse pointers will be created here -->
</div>

<canvas id="paper" width="1000" height="600" style="border:2px solid;">
    Your browser needs to support canvas for this to work!
</canvas>

<hgroup id="instructions">      
    <h1>Draw anywhere!</h1>
    <h2>You will see everyone else who's doing the same.</h2>
    <h3>Tip: if the stage gets dirty, simply reload the page</h3>
</hgroup>

<!-- JavaScript includes. Notice that socket.io.js is served by node.js -->
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script src="javascripts/script.js"></script>

■ NODE- 控制台:

debug: broadcasting packet
debug: xhr-polling received data packet 5:::{"name":"mousemove","args":[{"x":181,"y":139,"drawing":false,"id":599253111261}]}
debug: broadcasting packet
debug: setting request GET /socket.io/1/websocket/IuToQtNbcjsODD1VQjSa
debug: set heartbeat interval for client IuToQtNbcjsODD1VQjSa
debug: websocket writing 7:::1+0
warn: client not handshaken client should reconnect
info: transport end (error)
debug: set close timeout for client IuToQtNbcjsODD1VQjSa
debug: cleared close timeout for client IuToQtNbcjsODD1VQjSa
debug: cleared heartbeat interval for client IuToQtNbcjsODD1VQjSa
debug: discarding transport
debug: clearing poll timeout
debug: discarding transport
debug: setting request GET /socket.io/1/websocket/IuToQtNbcjsODD1VQjSa
debug: set heartbeat interval for client IuToQtNbcjsODD1VQjSa
debug: set close timeout for client IuToQtNbcjsODD1VQjSa
info: socket error Error: write Unknown system errno 10058
    at errnoException (net.js:769:11)
    at Socket._write (net.js:551:19)
    at Socket.write (net.js:510:15)
    at WebSocket.onSocketConnect (C:\public_html\yeahjs\node_modules\socket.io\lib\transports\websocket\hybi-16.js:132:17)
    at WebSocket.Transport.handleRequest (C:\public_html\yeahjs\node_modules\socket.io\lib\transport.js:71:10)
    at WebSocket.Transport (C:\public_html\yeahjs\node_modules\socket.io\lib\transport.js:31:8)
    at new WebSocket (C:\public_html\yeahjs\node_modules\socket.io\lib\transports\websocket\hybi-16.js:59:13)
    at new WebSocket (C:\public_html\yeahjs\node_modules\socket.io\lib\transports\websocket.js:31:17)
    at Manager.handleClient (C:\public_html\yeahjs\node_modules\socket.io\lib\manager.js:660:19)
    at Manager.handleUpgrade (C:\public_html\yeahjs\node_modules\socket.io\lib\manager.js:617:8)
debug: xhr-polling received data packet 5:::{"name":"mousemove","args":[{"x":200,"y":108,"drawing":true,"id":599253111261}]}
debug: broadcasting packet
debug: xhr-polling received data packet 0::
debug: got disconnection packet
info: transport end by forced client disconnection
info: transport end (booted)
4

0 回答 0