0
に私はそうのようなsocket.ioサーバーを作成しています:接続が第三者socket.ioサーバー
var http = require('http');
var io = require('socket.io');
var port = 8080;
var server = http.createServer(function(req, res){
res.writeHead(200,{ 'Content-Type': 'text/html' });
res.end('<h1>Hello Socket Lover!</h1>');
});
server.listen(port);
// Create a Socket.IO instance, passing it our server
var socket = io.listen(server);
// Add a connect listener
socket.on('connection', function(client){
console.log('Connection to client established');
// Success! Now listen to messages to be received
client.on('message',function(event){
console.log('Received message from client!',event);
});
client.on('disconnect',function(){
clearInterval(interval);
console.log('Server has disconnected');
});
});
console.log('Server running at http://127.0.0.1:' + port + '/');
をサーバが、私はこのようなJSを介して接続していたときただし、正常に動作して起動します:
$(function(){
var socket = io();
socket.connect('http://localhost:8080');
});
接続していないので、devツールコンソールでこれを取得しています。
polling-xhr.js:264 GET http://file/socket.io/?EIO=3&transport=polling&t=Lz53lhL net::ERR_NAME_NOT_RESOLVED
私はこのようなsocket.io.jsロードしています:あなたはあなたのURLを渡す必要が
$(function(){
var socket = io('http://localhost:8080');
});
に
<script src="http://127.0.0.1:8080/socket.io/socket.io.js"></script>
ありがとう、ありがとう! – gitterio