简体   繁体   English

连接到服务器时出错:未定义套接字io

[英]error on connecting to the server : socket io is not defined

i know there's been couple of question about the same problem , i've already check them . 我知道关于同一问题有几个问题,我已经检查过了。

i have very simple node.js chat app 我有一个非常简单的node.js聊天应用程序

i have a server running on 8000 port and it works fine 我有一台在8000端口上运行的服务器,并且工作正常

my client pages are html , they are running on apache and i'm using socket.io to connect them to the server and it works fine on the local host 我的客户页面是html,它们在apache上运行,我正在使用socket.io将它们连接到服务器,并且在本地主机上运行良好

but when i upload the app on the server i keep on getting this error in the firebug 但是当我在服务器上上传应用程序时,我不断在萤火虫中收到此错误

io is not defined
var socket = io.connect('http://atenak.com:8000/');

or sometimes it doesn't show that but when i try to broadcast message from cliend i get this error : 有时它没有显示出来,但是当我尝试从客户端广播消息时,出现此错误:

socket is undefined
socket.emit('msg', { data: msg , user:'max' });

the only difference is i've changed the localhost with atenak.com ! 唯一的区别是我已使用atenak.com更改了localhost!

here is my html code 这是我的HTML代码

var socket = io.connect('http://atenak.com:8000/');
    var user = 'jack';
  socket.on('newmsg', function (data) {
       if(data.user == user )
       {
           $('#container').html(data.data);
       }
  });

     function brodcast(){
           var msg = $('#fild').val();
          socket.emit('msg', { data: msg , user:'max' });
      }

</script>
</head>
<body>
<div id="container">  </div>
   <input id="fild"  type="text">  <input name="" type="button" onClick="brodcast();">

</body> 

i have included the sockt.io.js 我已经包括了sockt.io.js

src="http://atenak.com:8000/socket.io/socket.io.js"

and server is running ok which means socket.io is installed on the server 并且服务器运行正常,这意味着在服务器上安装了socket.io

here is the live page 这是实时页面

http://atenak.com/client.html

I'm getting: 我越来越:

> Uncaught ReferenceError: io is not defined client.html:7
x GET http://atenak.com:8000/socket.io/socket.io.js 

indicating that your page cannot load http://atenak.com:8000/socket.io/socket.io.js ; 指示您的页面无法加载http://atenak.com:8000/socket.io/socket.io.js ; indeed, if you try to load that URL in the browser, you get a connection error. 实际上,如果您尝试在浏览器中加载该URL,则会出现连接错误。 Make sure that your Node.js server (running Socket.IO) is accessible (eg ports not being blocked by a firewall, etc). 确保您的Node.js服务器(正在运行Socket.IO)可访问(例如,端口未被防火墙阻止等)。

Seems port 8000 is not open on your host as per links below 根据下面的链接,似乎主机上的端口8000未打开

Reverse ip check for atenak.com and Open port check 反向IP检查atenak.com开放端口检查

Socket.io need a javascript file and this file does not load correctly. Socket.io需要一个javascript文件,并且该文件无法正确加载。

Here is the url: http://atenak.com:8000/socket.io/socket.io.js 这是网址: http : //atenak.com : 8000/ socket.io/ socket.io.js

In this file is defined the îo object. 在此文件中定义îo对象。

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

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