最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - node.js Socket io "Reference error io is not defined" - Stack Overflow

programmeradmin2浏览0评论

I'm working on a chat program, I'm still in the beginning of making it but when I try to connect to the server from the console on google chrome it says a reference error io is not defined.

client

<!DOCTYPE html> 
<html>
<head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    <title>Chat</title>

</head>

<body>

    <div class="chat">
        <input type="text" class="chat-name" placeholder="Enter your name">
        <div class="chat-messages">
            <div class="chat-message">

            </div>
        </div>
        <textarea placeholder="type your message" class="chat-textarea"></textarea>
        <div class="chat-status">Status: <span>Idle</span></div>
    </div>


    <script>src="http://localhost:8080/socket.io/socket.io.js"</script>

</body>
</html>

server.js

var mongo = require('mongodb').MongoClient,
client = require('socket.io').listen(8080);
console.log("Server is running on port 8080");

I'm working on a chat program, I'm still in the beginning of making it but when I try to connect to the server from the console on google chrome it says a reference error io is not defined.

client

<!DOCTYPE html> 
<html>
<head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    <title>Chat</title>

</head>

<body>

    <div class="chat">
        <input type="text" class="chat-name" placeholder="Enter your name">
        <div class="chat-messages">
            <div class="chat-message">

            </div>
        </div>
        <textarea placeholder="type your message" class="chat-textarea"></textarea>
        <div class="chat-status">Status: <span>Idle</span></div>
    </div>


    <script>src="http://localhost:8080/socket.io/socket.io.js"</script>

</body>
</html>

server.js

var mongo = require('mongodb').MongoClient,
client = require('socket.io').listen(8080);
console.log("Server is running on port 8080");
Share Improve this question asked Jul 23, 2014 at 12:26 frostyfrosty 631 silver badge9 bronze badges 1
  • I am not getting variable io being used anywhere. is it your full code? – Mritunjay Commented Jul 23, 2014 at 12:31
Add a ment  | 

1 Answer 1

Reset to default 7

It's because of this:

<script>src="http://localhost:8080/socket.io/socket.io.js"</script>

It's a standard JS import. It should look like this:

<script src="http://localhost:8080/socket.io/socket.io.js"></script>
发布评论

评论列表(0)

  1. 暂无评论