Эй, я новичок в сокете и узле, и я играю с чатом, используя socket.io.Socket.io integration Node
Вот мой index.js файл:
var app = require('express')();
var http = require('http').Server(app);
app.get('/', function(req, res) {
//route handler serve index.html file
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket) {
console.log('A user has connected');
socket.on('disconnect', function() {
console.log("A user has disconnected");
})
})
http.listen(3000, function() {
console.log('listening on port 3000');
});
** Вот мой index.html: **
<html>
<head>
<title> Chat </title>
<script src="https://cdn.socket.io/socket.io-1.0.0.js"></script>
<script>
var socket = io();
</script>
</head>
<body>
<ul id="messages"></ul>
<form action="">
<input id="m" autocomplete="off"/> <button> Send </button>
</form>
</body>
я получаю Опорной ошибки говоря что io не определено. Я попытался связать сокет как cdn и как мой url сервера.
Требуется также socket.io на сервере. Попробуйте установить socket-io и добавьте следующий код '' 'var io = require ('socket.io') (app);' ''. –
@ HimaniAgrawal спасибо, это сработало! – rxa