0

Ok so I'm basically having the same problem as this. But the answers given there don't work for me. So let me re-explain my problem. First of all, here's my code:
Server-Side Javascript (app.js)

var io = require('socket.io');
...
var sio = io.listen(app);


Client-Side Javascript (client.js)

3: var socket = (s)io.connect('http://localhost:3000');
//the (s) represents testing with and without the s out of desperateness :)

Client-Side Template (Jade)

script(src='/socket.io/socket.io.js')
script(src='/javascripts/client.js')

So from what I've read it seems like socket.io should be handling putting the socket.io.js file there but I'm guessing that I have something configured wrong because it's not doing that. Anyways the errors I get with this are:

GET http://localhost:3000/socket.io/socket.io.js 404 (Not Found)
Uncaught ReferenceError: io is not defined - client.js line 3

After doing some research it seemed that I could change the jade file to link directly to a stable file. So by changing my code to this:
Client-Side Template (Jade)

script(src='http://cdn.socket.io/stable/socket.io.js')
script(src='/javascripts/client.js')

Then the error that I get from this is:

Uncaught TypeError: Object #<Object> has no method 'connect' - client.js line 3

I've been trying to figure this out for hours now. And it seems that I need to have socket.io-client so I made sure that it is installed. I dunno if this will but I am using Express.js as well and I will give you the layout of my files.
/project

app.js  /node_modules  package.json  /public  /routes  /views

/project/node_modules

/connect  /express  /jade  /jquery  /socket.io  /stylus

/project/node_modules/socket.io

/benchmarks  index.js  Makefile       package.json  restrict_jsonp.patch
History.md   /lib      /node_modules  Readme.md

/project/node_modules/socket.io/node_modules

/policyfile  /redis  /socket.io-client

/project/public

/images  /javascripts  /jquery  /stylesheets

/project/public/javascripts

client.js

Anyways, any help would be greatly appreciated! :)


I prefer to do a variation of 1, where I fill three arrays, indicating not only the current state, but also which keys just went down and which keys just went up. This allows me to easily check for those events in code (without comparing to the previous snapshot), but, most importantly, it won't miss events that last less than a frame. For example, if your game is running at 10 fps due to a slow machine, the user might press and release an important key between two calls of your update routine, and then your system will never register it. This is extremely frustrating.

SDL also sends key events when the key is held down, which allow you to have multiple key down events for each key up. I find this particularly useful when implementing keyboard scrolling through a list of items, e.g. a keyboard-controlled menu.

4

1 に答える 1

1

Felix Loether が指摘したように、Express の API は 2.* から 3.* に変更されました。自分のコードを再加工する最善の方法を見つけようと何時間も費やした後、私は Express を以前のバージョンに再インストールすることにしました。これを行う:

npm install express@2.5.8 -g

Express 2.* には (今日の時点で) より多くのサポートがあるため、まだ学習中なので、以前のバージョンを使用することをお勧めします。

于 2012-07-31T21:47:20.717 に答える