Socket.io and Laravel cant connect to socket

Posted 4 years ago by sijdesign

Hi all,

i have searched the whole WWW and i just cant find any good tutorial on how to setup socket.io and laravel.

Right now i have my server.js file

var express = require('express'),
    app = express(),
    server = require('http').createServer(app),
    io = require('socket.io').listen(server),
    logger = require('winston'),
    port = 3000;


server.listen(port);


// Logger config
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {colorize: true, timestamp: true});
logger.info('SocketIO > listening on port ' + port);

io.on('connection', function(socket){
    console.log('a user connected');
});

my APP url for laravel is

APP_URL=http://localhost

My client site has this in my layout file

<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io('http://localhost:3000');
</script>

I do a vagrant ssh and in my project folder i run this

node server.js

and it says

2015-05-10T09:31:21.161Z - info: SocketIO > listening on port 3000

i refresh my website and in console it says

ERROR GET http://domain.app:8000/socket.io/socket.io.js 
ERROR Uncaught ReferenceError: io is not defined

in my URL i have this: http://domain.app:8000/ Can anyone see what im doing wrong here :)?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.