Javascript 如何使用Pusher将用户的存款和取款详细信息从客户端发送到Node.js(express)服务器?
我订阅“我的频道”并绑定到客户端中的“我的事件” pusher.htmlJavascript 如何使用Pusher将用户的存款和取款详细信息从客户端发送到Node.js(express)服务器?,javascript,node.js,websocket,pusher,pusher-js,Javascript,Node.js,Websocket,Pusher,Pusher Js,我订阅“我的频道”并绑定到客户端中的“我的事件” pusher.html <!DOCTYPE html> <head> <title>Pusher Test</title> <script src="https://js.pusher.com/5.0/pusher.min.js"></script> <script> // Enable pusher logging - don't incl
<!DOCTYPE html>
<head>
<title>Pusher Test</title>
<script src="https://js.pusher.com/5.0/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('******', {
cluster: 'ap2',
forceTLS: true
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(JSON.stringify(data));
});
</script>
</head>
<body>
<h1>Pusher Test</h1>
<p>
Try publishing an event to channel <code>my-channel</code>
with event name <code>my-event</code>.
</p>
</body>
我正在“我的频道”中触发“我的事件”,并发送一条消息“hello world”
server.js
var pusher = new Pusher({
appId: '****',
key: '****',
secret: '******',
cluster: 'ap2',
encrypted: true
});
pusher.trigger('my-channel', 'my-event', {
"message": "hello world"
});
对于这段代码,我在客户端收到一条警报消息。i、 例如,我的服务器正在向客户端发送消息,但我的问题是,我希望整个过程以另一种方式进行,我希望客户端向服务器发送消息,以及如何在服务器中接收消息?如何使用node.js使用pusher来实现这一点
谢谢 频道提供的客户端库只能订阅频道并使用事件(它们还可以向其他客户端发送事件)-它们不能向服务器触发事件。 服务器库只能触发事件-它们不能订阅通道 可以通过使用和配置必要的工具来实现解决方案 更多信息可在推送器通道中找到