javascript - Mixing Laravel(PHP) with socket.io -
we have laravel project, however, parts of app lot of polling decided introduce socket.io app. laravel rests on apache listens on port 80 (we utilize jquery , bootstrap in front end end). our local test hostname test.localhost.com. node server server created listens on port 1000, express , socket.io installed.
in our laravel page, have next include: <script src="//localhost:1000/socket.io/socket.io.js"></script>
. test, have next code in our front end end:
<script> $(document).ready(function() { var socket = io(); $("#msg").keyup(function(event) { if (event.keycode === 13) { socket.emit($("#msg").val()); $("#msg").val(''); } }); }); </script>
however, when seek send message, nil received on node side, in chrome console notice following:
get http://test.localhost.com/socket.io?eio=3&transport=polling&t=1413006253169-84 404 (not found) , error on line 2680 of socket.io.js. open file , go line 2680 , see xhr.send(this.data);
. what's going on? can not mix 2 code bases? , why trying @ test.localhost.com when in import i'm using localhost:1000 (different host , different port)?
ok got it. when create connection, socket.io assumes you're connecting localhost:80. if not, can specify server host explicitly:
var socket = io('http://localhost:1000');
javascript php node.js websocket socket.io
No comments:
Post a Comment