zeromy quick start - python
软件:
pip install pyzmq
代码:
==server.py
#
# Hello World server in Python
# Binds REP socket to tcp://*:5555
# Expects "Hello" from client, replies with "World"
#
import zmq
import time
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
while True:
# Wait for next request from client
message = socket.recv()
print ("Received request: ", message)
# Do some 'work'
time.sleep (1) # Do some 'work'
# Send reply back to client
socket.send_string("World")
==client.py
#
# Hello World client in Python
# Connects REQ socket to tcp://localhost:5555
# Sends "Hello" to server, expects "World" back
#
import zmq
context = zmq.Context()
# Socket to talk to server
print ("Connecting to hello world server..." )
socket = context.socket(zmq.REQ)
socket.connect ("tcp://localhost:5555")
# Do 10 requests, waiting each time for a response
for request in range (1,10):
print ("Sending request ", request,"..." )
socket.send_string ("Hello")
# Get the reply.
message = socket.recv()
print ("Received reply ", request, "[", message, "]" )
步骤
打开一个命令行,执行python server.py
打开一个命令行,执行python client.py
参考:
https://blog.csdn.net/kent45/article/details/10397917
zeromy quick start - python的更多相关文章
- Quick Reference Card Urls For Web Developer
C# C# Cheatsheet & Notes Coding Guidelines for C# 3.0, 4.0, 5.0 Core C# and .NET Quick Reference ...
- A look at WeChat security
原文地址:http://blog.emaze.net/2013/09/a-look-at-wechat-security.html TL;DR: Any (unprivileged) applicat ...
- Red Hat Enterprise Linux 8正式发布
现在CENTOS 8还没有发布. 了解其主要特点. https://developers.redhat.com/blog/2019/05/07/red-hat-enterprise-linux-8-n ...
- (转) Quick Guide to Build a Recommendation Engine in Python
本文转自:http://www.analyticsvidhya.com/blog/2016/06/quick-guide-build-recommendation-engine-python/ Int ...
- [文摘]Quick Start to Client side COM and Python
摘自:PyWin32.chm Introduction This documents how to quickly start using COM from Python. It is not a t ...
- What does Quick Sort look like in Python?
Let's talk about something funny at first. Have you ever implemented the Quick Sort algorithm all by ...
- Python Quick list dir
昨天 Python释放了 3.5 ,添加了 os.scandir 根据文档该API比os.listdir快Docs which speeds it up by 3-5 times on POSIX s ...
- Python Quick Start
1.安装Python 官网下载python: https://www.python.org/ 有2.x 3.x版本, 注意,python3.0不向下兼容2.x版本,有很多包3.0不提供 下载完后直接点 ...
- 快速排序算法回顾 --冒泡排序Bubble Sort和快速排序Quick Sort(Python实现)
冒泡排序的过程是首先将第一个记录的关键字和第二个记录的关键字进行比较,若为逆序,则将两个记录交换,然后比较第二个记录和第三个记录的关键字.以此类推,直至第n-1个记录和第n个记录的关键字进行过比较为止 ...
随机推荐
- mySql单列索引与联合索引的区别
引自https://my.oschina.net/857359351/blog/658668 第一张表gift和索引为联合索引,如图: 第二张表gift2为单列索引,如图: 下面开始进行测试: 相同的 ...
- 单字段去重 distinct 返回其他多个字段
select a.*, group_concat(distinct b.attribute_name) from sign_contract_info a left join sign_temp_at ...
- hdu3001(状压dp,三进制)
Travelling Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- day 67 django orm的基础
django项目 安装: 创建项目 配置(setting,static,csrf) 创建app,python manage.py startapp app1 三部分 urls.py路由配置 1,普通正 ...
- Python 连接 redis 模块
redis 模块使用可以分类为: 连接方式 连接池 操作 String操作 Hash操作 List操作 Set操作 Sort Set操作 管道 发布订阅 (1)操作模式 redis提供两个类Redis ...
- [Mac]ssh免密登陆配置
在已经有公钥和私钥的情况下,只需要以下三步即可实现免密登陆: 1.将已有rsa公钥和私钥拷贝到~/.ssh目录下. 2.编辑配置文件:vim ~/.ssh/config,内容如下: Host xxx ...
- golang flag简单用法
package main import ( "flag" "strings" "os" "fmt" ) var ARGS ...
- HDU 6060 17多校3 RXD and dividing(树+dfs)
Problem Description RXD has a tree T, with the size of n. Each edge has a cost.Define f(S) as the th ...
- CHAP认证(双向)
实验要求:掌握CHAP认证配置 拓扑如下: R1enable 进入特权模式configure terminal 进入全局模式hostname R1 设置主机名 interface s0/0/0 ...
- Linux shell脚本中shift
Linux shell脚本中shift的用法说明 shift命令用于对参数的移动(左移),通常用于在不知道传入参数个数的情况下依次遍历每个参数然后进行相应处理(常见于Linux中各种程序的启动脚本). ...