gpt4 book ai didi

node.js - socket.io nodejs 客户端显示 "GET http://localhost:8888/socket.io/1/?t=1342788870007 404 (Not Found) "

转载 作者:搜寻专家 更新时间:2023-11-01 00:09:05 24 4
gpt4 key购买 nike

客户端错误是:

GET http://localhost:8888/socket.io/1/?t=1342788870007 404 (Not Found)socket.io.js:1632

Socket.handshake socket.io.js:1632
Socket.connect socket.io.js:1671
Socket socket.io.js:1530
io.connect socket.io.js:91

(匿名函数)

我的客户端js:

var socket = new io.connect("http://localhost", 8888);

socket.on("chatRoom", function(data){
$("#log").html($("#log").html() + "<br>" + data);
})

$("#chatform").submit(function (event) {
event.preventDefault();
socket.emit('chatRoom', $("#chat").val())
})

我的服务器是:

var express = require('../node_modules/express'),
app = express.createServer(),
io = require('../node_modules/socket.io').listen(app),
fs = require('fs');

app.use(express.bodyParser());

var port = 8888;

// get html page ok
app.get('/html/*', function (req, res) {
res.sendfile(__dirname + '/html/' + req.params[0]);
});

// chat
io.sockets.on('connection', function (socket) {
socket.on("login", function(message){
socket.emit('chatRoom', "sombody connect");
})

socket.on("chatRoom", function(data){
socket.emit('chatRoom',"from server");
})
})

app.listen(port);

谁能告诉我哪里错了?我在服务器端使用 express+socket.io,在客户端使用 socket.io.js服务器和客户端都在本地主机

最佳答案

正如@ebohlman 提到的

尝试使用

var socket = io.connect('http://localhost:8888');

在你的客户端 js 而不是

var socket = new io.connect("http://localhost", 8888);

关于node.js - socket.io nodejs 客户端显示 "GET http://localhost:8888/socket.io/1/?t=1342788870007 404 (Not Found) ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11580016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com