POCO C++ SOCKET
- // client program
- #include "Poco/Net/DatagramSocket.h"
- #include "Poco/Net/SocketAddress.h"
- #include "Poco/Timestamp.h"
- #include "Poco/DateTimeFormatter.h"
- int testUdpClient(){
- const char* ipaddr = "192.168.81.140"; //"192.168.81.140"
- Poco::Net::SocketAddress sa(ipaddr, 5004);
- Poco::Net::DatagramSocket dgs(Poco::Net::IPAddress::IPv4);
- dgs.connect(sa);
- //dgs.bind(sa);
- std::string syslogMsg;
- Poco::Timestamp now;
- syslogMsg = Poco::DateTimeFormatter::format(now, "<14>%w %f %H:%M:%S Hello,world!");
- dgs.sendBytes(syslogMsg.data(), syslogMsg.size());
- return 0;
- }
- /// server program
- #include "Servers.h"
- #include "Poco/Net/DatagramSocket.h"
- #include "Poco/Net/SocketAddress.h"
- #include "Poco/Timestamp.h"
- #include "Poco/DateTimeFormatter.h"
- int testDatagramSocket(){
- Poco::Net::SocketAddress sa(Poco::Net::IPAddress(), 5004);
- Poco::Net::DatagramSocket dgs(sa);
- char buffer[1024]; // 1K byte
- while(1){
- Poco::Net::SocketAddress sender;
- int n = dgs.receiveFrom(buffer, sizeof(buffer)-1, sender);
- buffer[n] = '\0';
- std::cout << sender.toString() << ":" << buffer << std::endl;
- }
- return 0;
- }
tcp
- // client program
- #include "Poco/Net/SocketAddress.h"
- #include "Poco/Net/StreamSocket.h"
- #include "Poco/Net/SocketStream.h"
- #include "Poco/StreamCopier.h"
- #include <iostream>
- int main(int argc, char** argv){
- const char* ipaddr = "192.168.81.140"; // the server address.
- Poco::Net::SocketAddress sa(ipaddr, 5004); // the server port.
- Poco::Net::StreamSocket socket(sa);
- Poco::Net::SocketStream str(socket);
- // Writes all bytes readable from str into std::cout, using an internal buffer.
- Poco::StreamCopier::copyStream(str, std::cout);
- return 0;
- }
- // server program
- #include "Poco/Net/ServerSocket.h"
- #include "Poco/Net/StreamSocket.h"
- #include "Poco/Net/SocketStream.h"
- #include "Poco/Net/SocketAddress.h"
- int main(int argc, char** argv){
- Poco::Net::ServerSocket srv(5004); // does bind + listen
- for(;;){
- Poco::Net::StreamSocket ss = srv.acceptConnection();
- Poco::Net::SocketStream str(ss);
- // flush() make sure the file stream is updated with the data.
- // endl() puts a newline and then uses flush().
- str << "HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "\r\n"
- "<html><head><title>My 1st Web Server</title></head>"
- "<body><h1>Hello,Wordl!</h1></body></html>"
- "\r\n"
- << std::flush;
- }
- return 0;
- }
POCO C++ SOCKET的更多相关文章
- POCO库中文编程参考指南(3)Poco::Net::Socket
POCO库中文编程参考指南(3)Poco::Net::Socket 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.c ...
- c++ poco StreamSocket tcpclient测试用例
1.代码 #include <iostream> #include "Poco/Net/Socket.h" #include "Poco/Net/Stream ...
- POCO库中文编程参考指南(8)丰富的Socket编程
POCO库中文编程参考指南(8)丰富的Socket编程 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# ...
- 关于 Poco::TCPServer框架 (windows 下使用的是 select模型) 学习笔记.
说明 为何要写这篇文章 ,之前看过阿二的梦想船的<Poco::TCPServer框架解析> http://www.cppblog.com/richbirdandy/archive/2010 ...
- 使用GDB 追踪依赖poco的so程序,core dump文件分析.
前言 在windows 下 系统核心态程序蓝屏,会产生dump文件. 用户级程序在设置后,程序崩溃也会产生dump文件.以方便开发者用windbg进行分析. so,linux 系统也有一套这样的东东- ...
- poco网络库分析,教你如何学习使用开源库
Poco::Net库中有 FTPClient HTML HTTP HTTPClient HTTPServer ICMP Logging Mail Messages NetCore NTP OAuth ...
- Poco::TCPServer框架解析
Poco::TCPServer框架解析 POCO C++ Libraries提供一套 C++ 的类库用以开发基于网络的可移植的应用程序,功能涉及线程.文件.流,网络协议包括:HTTP.FTP.SMTP ...
- 如何编译POCO
Poco C++库是: 一系列C++类库,类似Java类库,.Net框架,Apple的Cocoa; 侧重于互联网时代的网络应用程序 使用高效的,现代的标准ANSI/ISO C++,并基于STL 高可移 ...
- POCO TCPServer 解析
POCO C++ Libraries提供一套 C++ 的类库用以开发基于网络的可移植的应用程序,功能涉及线程.文件.流,网络协议包括:HTTP.FTP.SMTP 等,还提供 XML 的解析和 SQL ...
随机推荐
- mysql学习第三天笔记
连接连接是在多个表之间通过一定的连接条件,使表之间发生关联,进而能从多个表之间获取数据.在 WHERE子句中书写连接条件. 如果在多个表中出现相同的列名,则需要使用表名作为来自该表的列名的前缀. N个 ...
- 初见akka-01
最近在学习akka,在看rpc相关的东西,有点脑子疼,哈哈 1.需求: 目前大多数分布式架构底层通信是通过RPC实现的,RPC框架非常多, 比如我们学过的Hadoop项目的RPC通信框架,但是Hado ...
- Idea中maven依赖图查看
技术交流群: 233513714 使用Intellij idea,想看看它的maven依赖图,根据eclipse的经验,不是很容易能找到Intellij idea对应的功能.在打开的pom.xml文件 ...
- leetcode 【 Merge Two Sorted Lists 】 python 实现
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- springboot注解使用,分页sql
https://blog.csdn.net/KingBoyWorld/article/details/78948304
- hp raid json
hp机器均已在装OS之前划好raid,统一规格为2*480G SSD, 12*4T SATA ,2*1.6T SSD,其中2*480G SSD做系统盘,划分raid1 已知disk controlle ...
- 【2017】KK English
2017/11/24 Regardless of the enormous amount of photos shared on Wechat or Face book, modern city dw ...
- centos下vsftpd登录后无法看见文件,无法创建文件及文件夹
centos下vsftpd不能显示文件,不能创建文件及文件夹 这是由于selinux的机制 运行如下命令查看: [root@SZCLC6X-AMP-4393 www]# getsebool -a|gr ...
- weex & web app & vue
weex & web app & vue https://weex-project.io/tools/playground.html https://weex.apache.org/ ...
- MPS添加管理设备实例NS的过程
MPS添加管理设备实例NS的过程 MPS添加实例NS设备节点: > show snmp community Done > > add snmp community public al ...