问题描述
我主要按照以下帖子使用 SockJS 实现推送通知,
I've mainly followed below posts for implementing push notifications using SockJS,
Java Web 应用推送通知,SockJS 客户端, SockJS Java 服务器.
我的 sockJS 客户端是:
My sockJS client is:
var sock = new SockJS("http://localhost:8080/pusher");
sock.onmessage = function(event) {
console.log("message: " + event.data);
alert('received message echoed from server: ' + event.data);
};
*服务器正在侦听相同的端口 8080.但是在运行时出现错误 404:
*Server is listening same port 8080. But while running I got error 404:
GET http://localhost:8080/pusher/info 404 (Not Found)
这篇关于 StackOverflow 的帖子并没有解决我的问题.请检查我遗漏了什么.我是否需要注册客户端或发布服务器才能启用推送通知.提前致谢!
This post on StackOverflow doesn't solve my problem. Please check what I'm missing.Do I need to register client or publish server to enable the push notifications. Thanks in advance!
推荐答案
你必须遵循这个模式:https://github.com/sockjs/sockjs-node/blob/master/examples/express-3.x/server.js
密切注意调用app.listen
不起作用的事实,你必须调用server.listen
.所以 .listen
调用必须在 http 实例上,而不是在 express 实例上.
Pay close attention to the fact that calling app.listen
will NOT work, you must call server.listen
. So the .listen
call must be on the http instance, not on the express instance.
这篇关于SockJS - '/info' 在连接服务器时导致 Http 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!