javascript - 如何使用 Pusher 将用户的存款和取款详细信息从客户端发送到 Node.js (express) 服务器?
问题描述
我正在订阅“我的频道”并绑定到客户端中的“我的事件”。
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 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
服务器.js
var pusher = new Pusher({
appId: '****',
key: '****',
secret: '******',
cluster: 'ap2',
encrypted: true
});
pusher.trigger('my-channel', 'my-event', {
"message": "hello world"
});
对于此代码,我在客户端收到一条警报消息。即,我的服务器正在向客户端发送消息,但我的问题是我希望整个过程以其他方式进行,我希望客户端向服务器发送消息以及如何在服务器中接收这些消息?如何使用 node.js 使用推送器来做到这一点。
谢谢!
解决方案
推荐阅读
- python - 如何使用 django 将用户个人资料字段(如电话号码、性别)公开隐藏在社交媒体应用程序中?
- django - 电子邮件激活(Django 项目)
- javascript - 如何在JavaScript中获取日期之间的日期差异
- rust - 发生移动是因为 `*arg` 的类型为 `String`,它没有实现 `Copy` 特征
- javascript - 根据月份过滤对象列表?
- javascript - Swiper React 的样式只有在调整窗口大小后才会生效
- c - 文件描述符的值可以超过最大打开的文件描述符软限制吗?
- java - 有没有办法将 verifyNoInteractions 与超时结合起来
- latex - CircuiTikZ:如何指定组件公差
- pyspark - Dataframe 写入 parquet 分区文件夹名称