node.js使用zmq通信
来源:互联网 发布:c语言能编写什么软件 编辑:程序博客网 时间:2024/04/29 16:48
server端
var zmq = require("zmq"); var socket = zmq.socket("req"); var counter = 0;// Just a helper function for logging to the console with a timestamp.function logToConsole (message) { console.log("[" + new Date().toLocaleTimeString() + "] " + message);}function sendMessage (message) { logToConsole("Sending: " + message); socket.send(message);}// Add a callback for the event that is invoked when we receive a message.socket.on("message", function (message) { // Convert the message into a string and log to the console. logToConsole("Response: " + message.toString("utf8"));});// Begin listening for connections on all IP addresses on port 9998.socket.bind("tcp://*:9998", function (error) { if (error) { logToConsole("Failed to bind socket: " + error.message); process.exit(0); } else { logToConsole("Server listening on port 9998"); // Increment the counter and send the value to the clients every second. setInterval(function () { sendMessage(counter++); }, 1000); }});
client端
var zmq = require("zmq"); var socket = zmq.socket("rep");// Just a helper function for logging to the console with a timestamp.function logToConsole (message) { console.log("[" + new Date().toLocaleTimeString() + "] " + message);}// Add a callback for the event that is invoked when we receive a message.socket.on("message", function (message) { // Convert the message into a string and log to the console. logToConsole("Received message: " + message.toString("utf8")); // Send the message back aa a reply to the server. socket.send(message);});// Connect to the server instance.socket.connect('tcp://127.0.0.1:9998');
0 0
- node.js使用zmq通信
- python使用zmq通信
- 使用zmq多次通信
- 如何在Windows server上使用Node.js正常运行ZMQ库
- node.js使用node-xmpp进行xmpp通信
- Node安装zmq
- ZeroMQ实例-使用ZMQ(ZeroMQ)进行局域网内网络通信
- 使用socket.io和node.js搭建及时通信系统
- zmq常用通信模式
- zmq技术--网络通信
- java与node.js通信
- Node.js - Node.js安装使用入门
- zmq安装与使用
- node js 安装使用
- 为什么使用Node.JS
- 开始使用node.js
- node.js使用mongodb
- node.js 使用 imagemagick
- 20个正则表达式
- hjr教程-DSP(三):关键字与伪指令
- sensor 详解(转载,用以记录)
- 【系统安装】双系统——Win7下安装linux系统详细步骤
- python面向对象
- node.js使用zmq通信
- 操作配置文件API函数
- python使用zmq通信
- 关于mysql优化和索引的故事
- 三维按钮样式
- Linux socket之二:面向连接的socket通信实现
- intent
- C#学习笔记之创建Xml文档
- 国内优秀的Android资源