开发者

Socketio wont run, getting io.connection not a function

开发者 https://www.devze.com 2023-04-11 21:58 出处:网络
Using this code on the client side: <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js\"></script>

Using this code on the client side:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
    <scri开发者_JAVA技巧pt src="http://cdn.socket.io/stable/socket.io.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
                var socket = io.connect('http://localhost:8888');
});
</script>

Getting this error:

"io.connect is not a function"

Any suggestions?


The answer was I had to use my external ip address for the server this script is running on.


The biggest problem is that http://cdn.socket.io/stable/socket.io.js is code for Socket.IO 0.6 and you are using the Socket.IO 0.7+ API.

The CDN has been deprecated and should no longer be used. Here is a wiki about how to serve the socket.io client in your HTML pages: https://github.com/LearnBoost/Socket.IO/wiki/How-do-I-serve-the-client

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号