How to run socket.io (client side only) on apache server

青春壹個敷衍的年華 提交于 2019-12-30 12:33:00

问题


I want to run client side of socket.io on my apache server.

I have uploaded the socket.io directory to my web server and tried the simple client connection example from the main site socket.io but its not working. I dont know what do I need to get it work and connect my running server.

I Hope, I have clearly explained my problem.

Thank you.


回答1:


Copy all the files in socket.io\node_modules\socket.io-client\dist to your apache server for example to the js folder. Then add the socket.io.min.js to your page.

<script src="js/socket.io.min.js" type="text/javascript"></script>
<script type="text/javascript">
    var socket = io.connect('http://localhost:3000');
    socket.on('news', function (data) {
        console.log(data);
    });
</script>



回答2:


Copy the distributable .js to your own javascript folder. In my case, I'm ussing xampp:

C:\xampp\htdocs\nodejs\node_modules\socket.io\node_modules\socket.io-client\dist


来源:https://stackoverflow.com/questions/11622853/how-to-run-socket-io-client-side-only-on-apache-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!