简体   繁体   English

如何在apache服务器上运行socket.io(仅客户端)

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

I want to run client side of socket.io on my apache server. 我想在我的apache服务器上运行socket.io的客户端。

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. 我已将socket.io目录上传到我的Web服务器,并尝试从主站点socket.io中的简单客户端连接示例,但它无法正常工作。 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. 谢谢。

Copy all the files in socket.io\\node_modules\\socket.io-client\\dist to your apache server for example to the js folder. socket.io\\node_modules\\socket.io-client\\dist所有文件复制到apache服务器,例如复制到js文件夹。 Then add the socket.io.min.js to your page. 然后将socket.io.min.js添加到您的页面。

<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>

Copy the distributable .js to your own javascript folder. 将可分发的.js复制到您自己的javascript文件夹中。 In my case, I'm ussing xampp: 就我而言,我正在使用xampp:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM