boost::asio 连接管理7
来源:互联网 发布:打印机端口名称是什么 编辑:程序博客网 时间:2024/05/21 23:34
newLISP提供了简单的方法让我创建多个进程。下面的程序创建10个进程,每个进程发送几个'a', 最后发送一个'q'.
(define (quit-for-error) ((println (net-error)) (exit)))(define (send-test) (set 'socket (net-connect "localhost" 8888)) (if (net-send socket "a") (println "send a successfully") (quit-for-error)) (if (net-send socket "a") (println "send a successfully") (quit-for-error)) (if (net-send socket "a") (println "send a successfully") (quit-for-error)) (if (net-send socket "a") (println "send a successfully") (quit-for-error)) (if socket (println (net-send socket "q")) (quit-for-error)) (exit))(spawn 'r1 (send-test))(spawn 'r2 (send-test))(spawn 'r3 (send-test))(spawn 'r4 (send-test))(spawn 'r5 (send-test))(spawn 'r6 (send-test))(spawn 'r7 (send-test))(spawn 'r8 (send-test))(spawn 'r9 (send-test))(spawn 'r10 (send-test))(until (sync 1000))(exit)
spawn 创建了子进程,用来执行函数send-test.
一共创建了10个进程。
until是一个等待,直到所有子进程都退出才返回。
现在运行测试程序:
newlisp ./parallel_text.lspsend a successfullysend a successfullysend a successfullysend a successfullysend a successfullysend a successfullysend a successfully1send a successfullysend a successfully1send a successfullysend a successfullysend a successfully1send a successfullysend a successfullysend a successfullysend a successfully1send a successfullysend a successfullysend a successfullysend a successfully1send a successfullysend a successfullysend a successfullysend a successfully1send a successfullysend a successfullysend a successfullysend a successfully1send a successfullysend a successfullysend a successfullysend a successfully1send a successfullysend a successfullysend a successfullysend a successfully1send a successfullysend a successfullysend a successfullysend a successfully1
服务程序显示如下:
./cppapplication_4 the number of connections is: 1the new connection object is starting now.correct data receivedthe number of connections is: 2the new connection object is starting now.correct data receivedthe number of connections is: 3the new connection object is starting now.correct data receivedcorrect data receivedcorrect data receivedcorrect data receivedcorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connectioncorrect data receivedwrong data received, char is:113closing the socket~Connectioncorrect data receivedcorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connectionthe number of connections is: 1the new connection object is starting now.correct data receivedcorrect data receivedcorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connectionthe number of connections is: 1the new connection object is starting now.correct data receivedcorrect data receivedcorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connectionthe number of connections is: 1the new connection object is starting now.correct data receivedcorrect data receivedcorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connectionthe number of connections is: 1the new connection object is starting now.correct data receivedcorrect data receivedcorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connectionthe number of connections is: 1the new connection object is starting now.the number of connections is: 2the new connection object is starting now.correct data receivedcorrect data receivedcorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connectioncorrect data receivedcorrect data receivedthe number of connections is: 2the new connection object is starting now.correct data receivedcorrect data receivedcorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connectioncorrect data receivedcorrect data receivedwrong data received, char is:113closing the socket~Connection
仔细检查,创建了10个连接,又关闭了10个连接。程序正常。好,下面考虑将服务器从单线程改成多线程模型。
- boost::asio 连接管理7
- boost::asio 连接管理1
- boost::asio 连接管理2
- boost::asio 连接管理3
- boost::asio 连接管理4
- boost::asio 连接管理5
- boost::asio 连接管理6
- boost::asio 连接管理8
- boost::asio 连接管理9
- boost::asio 连接管理10
- boost::asio 连接管理8
- boost::asio 连接管理11 如何关闭连接
- boost::asio设置同步连接超时
- boost::asio设置同步连接超时
- boost asio库 同步socket连接示例
- Boost Asio
- boost asio
- Boost.asio
- ldv内核模型源码--alloc
- 获取当前路径
- Linux进程状态解析之R、S、D、T、Z、X
- 向虚拟机传递信息(非技术文章,中转专用)
- 怎样正确 移除迭代器所指元素
- boost::asio 连接管理7
- 教你如何秒杀12306,JAVA程序抢票成功!分享~~~[附截图]
- HashMap原理
- 程序图片
- ubuntu通过主机的无线网卡上网问题
- 《思考的技术》笔记二
- C程序实现数字反转
- 无线安全
- ref和out