1

在 Express 3.x 上的 Windows 7 x64 位环境中安装 socket.io 包给我带来了很大的困难。

我不得不理清几十个或编译错误,我必须安装以下 Windows 7 包,安装过程输出没有错误:

  • Cygwin C++ 编译器
  • Cygin C++ 额外库
  • Microsoft Visual Studio 2010 速成版
  • 微软 .NET 框架 v2.0
  • Microsoft 性能工具包 Microsoft Windows SDK 7.1
  • 适用于 Windows SDK 7.1 的 Microsoft Visual C++ 2010 SP1 编译器更新。

(Visual Studio 编译器给了我一个警告 C4267(见下文))

尽管安装正确,但我仍然有客户端错误:

Error: io is not defined
var socket = io.connect('/');

我遵循了socket.io.js使用 app.js 由 nodejs 服务器提供服务的建议:

var express = require('express')
    , http = require('http');

var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);

玉文件中的客户端声明是:

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

我的 socket.io 客户端脚本部分是:

var socket = io.connect('/');

socket.io 安装到我和目录node-login所在的目录中。app/publicapp/server

socket.io 安装日志:

D:\dev\node-login>npm install socket.io
npm http GET https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/socket.io
npm http GET https://registry.npmjs.org/socket.io-client/0.9.11
npm http GET https://registry.npmjs.org/policyfile/0.0.4
npm http GET https://registry.npmjs.org/base64id/0.1.0
npm http GET https://registry.npmjs.org/redis/0.7.3
npm http 304 https://registry.npmjs.org/socket.io-client/0.9.11
npm http 304 https://registry.npmjs.org/base64id/0.1.0
npm http 304 https://registry.npmjs.org/policyfile/0.0.4
npm http 304 https://registry.npmjs.org/redis/0.7.3
npm http GET https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http GET https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/uglify-js/1.2.5
npm http 304 https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http 304 https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/zeparser/0.0.5
npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/zeparser/0.0.5
npm http 304 https://registry.npmjs.org/commander
npm http 304 https://registry.npmjs.org/options

> ws@0.4.25 install D:\dev\node-login\node_modules\socket.io\node_modules\socket
.io-client\node_modules\ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)


D:\dev\node-login\node_modules\socket.io\node_modules\socket.io-client\node_modu
les\ws>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\no
de_modules\node-gyp\bin\node-gyp.js" rebuild
  bufferutil.cc
..\src\bufferutil.cc(55): warning C4267: 'initializing' : conversion from 'size
_t' to 'unsigned int', possible loss of data [D:\dev\node-login\node_modules\so
cket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
..\src\bufferutil.cc(66): warning C4267: 'initializing' : conversion from 'size
_t' to 'unsigned int', possible loss of data [D:\dev\node-login\node_modules\so
cket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\Vivaldi\.node-gyp\0.8.17\deps\v8\include\v8.h(183): warning C4506: no
definition for inline function 'v8::Persistent<T> v8::Persistent<T>::New(v8::Ha
ndle<T>)' [D:\dev\node-login\node_modules\socket.io\node_modules\socket.io-clie
nt\node_modules\ws\build\bufferutil.vcxproj]
          with
          [
              T=v8::Object
          ]
     Creating library D:\dev\node-login\node_modules\socket.io\node_modules\soc
  ket.io-client\node_modules\ws\build\Release\bufferutil.lib and object D:\dev\
  node-login\node_modules\socket.io\node_modules\socket.io-client\node_modules\
  ws\build\Release\bufferutil.exp
  Generating code
  Finished generating code
  bufferutil.vcxproj -> D:\dev\node-login\node_modules\socket.io\node_modules\s
  ocket.io-client\node_modules\ws\build\Release\\bufferutil.node
  validation.cc
C:\Users\Vivaldi\.node-gyp\0.8.17\deps\v8\include\v8.h(183): warning C4506: no
definition for inline function 'v8::Persistent<T> v8::Persistent<T>::New(v8::Ha
ndle<T>)' [D:\dev\node-login\node_modules\socket.io\node_modules\socket.io-clie
nt\node_modules\ws\build\validation.vcxproj]
          with
          [
              T=v8::Object
          ]
     Creating library D:\dev\node-login\node_modules\socket.io\node_modules\soc
  ket.io-client\node_modules\ws\build\Release\validation.lib and object D:\dev\
  node-login\node_modules\socket.io\node_modules\socket.io-client\node_modules\
  ws\build\Release\validation.exp
  Generating code
  Finished generating code
  validation.vcxproj -> D:\dev\node-login\node_modules\socket.io\node_modules\s
  ocket.io-client\node_modules\ws\build\Release\\validation.node
socket.io@0.9.13 node_modules\socket.io
+-- base64id@0.1.0
+-- policyfile@0.0.4
+-- redis@0.7.3
+-- socket.io-client@0.9.11 (xmlhttprequest@1.4.2, uglify-js@1.2.5, active-x-obf
uscator@0.0.1, ws@0.4.25)

D:\dev\node-login>

为什么客户端找不到socket.io.js?

4

1 回答 1

2

在这里回答:https ://github.com/LearnBoost/socket.io/issues/944

改变这个

var server = http.createServer(app);

进入这个

var server = http.createServer(app).listen( 3000 );

此外,我真的很惊讶你安装它这么痛苦。我同意在 windows 上安装各种与 web 相关的东西比在 linux 上更痛苦,但是 node 和它附带的所有包都不是其中之一。至少我对它没有任何问题,简单的安装和包管理通过nmp使它像在 linux 上一样简单。

于 2013-01-13T08:44:03.747 回答