socket.io issue using sails.js

2019-08-09 16:08发布

问题:

I am trying to use socket.io with sails js. I understood that it was pretty straighforward and that sails provided an available socket.io structure out of the box. Howeve When I try to connect to my sails server from a distant client using

io.connect(http://localhost:1337)

It makes my server crash with the message:

/node_modules/express/node_modules/connect/lib/utils.js:216 return 0 == str.indexOf('s:') ^ TypeError: Cannot call method 'indexOf' of undefined

I am probably missing something but I don't understand what.... Any clue about this?

Thanks !

回答1:

Looks like you're missing some quotes in your io.connect() call, but I can't imagine that your client app wouldn't throw a syntax error if your code really was written like that. Verify you've got:

io.connect('http://localhost:1337');


回答2:

ahem... Did you had a look @ the doc : http://sailsjs.org/#!documentation/sockets this is quite self explanatory, but if you need any help