0

我正在使用带有socketstream的node.js。客户端js文件未加载,并且在调用服务器方法时,我在客户端获取ss未定义错误。

  This is my  app.js file

   var ss = require('socketstream'), 
  express = require('express');
  var app = express(); 
 // Code & Template Formatters 
 ss.client.formatters.add(require('ss-stylus')); 
 ss.client.templateEngine.use(require('ss-hogan')); 
   ss.client.define('main',
    { view: 'app.html', 
    css: ['libs/reset.css', 'app.styl'], 
   code: ['libs/jquery.min.js', 'app'], 
     tmpl: '*' }); 
 // Use Express to route requests 
  app.get('/', function(req, res){ 
  res.serveClient('main'); });
  server = app.listen(3000); 
  ss.start(server);
  // Append SocketStream middleware to the stack 
  app.stack = ss.http.middleware.stack.concat(app.stack);


   This is my server side method rpc method
     exports.actions = function(req, res, ss){

    return {

        saveUserInfo: function(name,pwd){
        console.log(name);
        console.log(pwd);
        res('name is '+name + '&'+'password is '+pwd);

      }

        }
       }
4

1 回答 1

0

ss.rpc 函数采用 rpc 文件的名称,后跟函数名称。例如,如果文件名为server/rpc/authentication.js,那么您可以从客户端调用它:

ss.rpc('authentication.saveUserInfo', name, pwd, function(response){
  console.log(response);
});
于 2012-12-31T10:56:16.420 回答