Skip to content

Socket.IO issue #373

Closed
jfelipe11 opened this Issue May 14, 2012 · 10 comments

3 participants

@jfelipe11

Juan@JUANXPS-PC ~/mensajeria (master)
$ node server.js

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'socket.io'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object. (c:\Users\Juan\mensajeria\server.js:1:73)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)

my server.js script:
var mdv = require("socket.io").listen(process.env['app_port'] || 3000);
mdv.sockets.on("connection",arrancar);

function arrancar(msg){
msg.on("nuevoMensaje",emitir);
}

function emitir(data){
mdv.sockets.emit("mensaje",data);
}

In my localhost works fine; but i try to put on nodester and i have errors..

Please help me.

Regards,

@alejandro
Collaborator

@jfelipe11 Hi! Did you try nodester npm install APPNAME socket.io, then restart the app?

@jfelipe11

Hi @alejandromg yes i did, but doesnt work... again have the same error...

this is my npm list...

Juan@JUANXPS-PC ~/mensajeria (master)
$ nodester npm list
nodester info list npm packages for app: mensajeria
nodester ├── g@1.0.0
nodester ├─┬ socket.io@0.9.6
nodester │ ├── policyfile@0.0.4
nodester │ ├── redis@0.6.7
nodester │ └─┬ socket.io-client@0.9.6
nodester │ ├─┬ active-x-obfuscator@0.0.1
nodester │ │ └── zeparser@0.0.5
nodester │ ├── uglify-js@1.2.5
nodester │ └── xmlhttprequest@1.2.2
nodester └─┬ ws@0.4.14
nodester ├── commander@0.5.2
nodester └── options@0.0.3
nodester

best regards,

@alejandro
Collaborator

That's weird! I just ran a test, and it's working. This is what I did:

> npm install socket.io --save
> # edit my server.js file adding  this line 
require('socket.io');
> git add -u
> git commit -am '[test] with socket.io'
> git push origin master
> nodester npm install APPNAME socket.io
> nodester app restart APPNAME

And it's working.

Edit: Why in your logs you said:

> node server

Are you running this locally? Well if you can you can get into freenode#nodester (we are there for help you) or irc.nodester.com

@jfelipe11

Hi @alejandromg thanks for your help.

But still i have errors, may be when i call the scripts...

I have this three files...

  1. cliente.html (outside nodester.com)

In the head...
< script src="http://msg.nodester.com:80/socket.io/socket.io.js" type="text/javascript">
< script src="cliente.js" type="text/javascript">
......

  1. cliente.js (outside nodester.com) var websocket = io.connect("http://msg.nodester.com:80"); websocket.on("mensaje",recibirMensaje);

function enviarMensaje(){
websocket.emit("nuevoMensaje",$("#id_mensaje").val());
}

function recibirMensaje(datosServidor){
$("#mensajes").html(datosServidor);
// check for notifications support
// you can omit the 'window' keyword
if (window.webkitNotifications) {
console.log("Notifications are supported!");
window.webkitNotifications.createNotification("", "Notificacion", datosServidor).show();
}
else {
console.log("Notifications are not supported for this Browser/OS version yet.");
}
}

function chequearpermisos(){

if (window.webkitNotifications.checkPermission() != 0) { // 0 is PERMISSION_ALLOWED
// function defined in step 2
window.webkitNotifications.requestPermission();
}
}

  1. server.js (inside nodester.com) var io=require("socket.io").listen(process.env['app_port'] || 3000); io.sockets.on("connection",arrancar);

function arrancar(msg){
msg.on("nuevoMensaje",emitir);
}

function emitir(data){
io.sockets.emit("mensaje",data);
}

First, i see two errors on the chrome console log:

1.GET http://msg.nodester.com/socket.io/socket.io.js 503 (Service Unavailable)
2.Uncaught ReferenceError: io is not defined =>i suppose this error is because does not load the socket.io.js library...

I run on my local machine and everything works fine, but in nodester doesn't work

regards,

@chrismatthieu
Collaborator

It looks like http://msg.nodester.com/ is returning a 503 too. What does your log say?
nodester app logs {appname}

@alejandro
Collaborator

I found a strange case where app_port is not working as we want I fixed it with a parseInt. This is working for me: https://gist.github.com/525f55a7a2c457af2981.

As Chris said, share your logs.

@jfelipe11

Hi @alejandromg @chrismatthieu thanks for your help...

@alejandromg the solution was successful... works fine right now... http://finalmsg.nodester.com/

Best regards,

This is the final script...

var PORT = parseInt(process.env['app_port'],10) || 3000;
var io = require("socket.io").listen(PORT);
io.sockets.on("connection",arrancar);
function arrancar(msg){
msg.on("nuevoMensaje",emitir);
}

      function emitir(data){
            io.sockets.emit("mensaje",data);
       }

//---------------- OR

var PORT = parseInt(process.env['app_port'],10) || 3000;
var io = require("socket.io").listen(PORT, function () {
io.sockets.on("connection",arrancar);
function arrancar(msg){
msg.on("nuevoMensaje",emitir);
}

    function emitir(data){
            io.sockets.emit("mensaje",data);
    }

});

@jfelipe11 jfelipe11 closed this May 15, 2012
@jfelipe11

Hi guys,
I have a problem but the logs is not available.

Juan@JUANXPS-PC ~/finalmsg (master)
$ nodester app logs finalmsg
nodester ERROR Fatal Error! API Response: {"status":"failure","message":"No logs
available."}
Reason: No logs available.

this is my code:

var PORT = parseInt(process.env['app_port'],10) || 3000;

var io = require("socket.io").listen(PORT);

io.sockets.on("connection",arrancar);

function arrancar(msg){
msg.on("nuevoMensaje",emitir);
}

function emitir(data){
io.sockets.emit("mensaje",data);
}

thanks in advance..

@jfelipe11

Hi again,
In nodester admin panel i clicked on "git reset" and works again.
Thanks..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.