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 ...
随机推荐
- java线程安全总结 - 2 (转载)
原文地址:http://www.jameswxx.com/java/%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E6%80%BB%E7%BB%93%EF%BC%88%E4 ...
- 使用MD5比较两个文件是否相同
MD5算法:是计算机广泛使用的一种哈希算法,将数据(如汉字)运算为另一固定长度值,用于确保信息传输完整一致.java,C++ 等多种编程语言都有MD5的实现,可直接使用. 文件MD5值:每个文件都可以 ...
- mysql in和exists性能比较和使用【转】
exists对外表用loop逐条查询,每次查询都会查看exists的条件语句,当 exists里的条件语句能够返回记录行时(无论记录行是的多少,只要能返回),条件就为真,返回当前loop到的这条记录, ...
- HEXO next live2d插件删除问题
title: HEXO next live2d插件删除问题 date: 2018-03-06 13:09:12 updated: tags: [hexo,next,建站,学习,前端技术,疑问] des ...
- bootstrap设计进度条和圆点
1.设计进度条.文字前面的圆点和图片 2.思路: (1)设计进度条 (a) 进度条有滚动效果,要加上类.active (b)进度条的颜色通过类.progress-bar-success来写,可以写成. ...
- easyui-datagrid单选模式下隐藏表头的全选框
easyui-datagrid可以不使用复选框来进行单选,直接使用onSelect和 singleSelect:true就可以实现单选,但是有一些用户会比较习惯使用勾选框,这时会加一列checkbox ...
- java编程-无锁初始化
private final Node<K,V>[] initTable() { Node<K,V>[] tab; int sc; while ((tab = table) == ...
- 【Deep Learning】林轩田机器学习技法
这节课的题目是Deep learning,个人以为说的跟Deep learning比较浅,跟autoencoder和PCA这块内容比较紧密. 林介绍了deep learning近年来受到了很大的关注: ...
- python - web自动化测试 - 元素操作 - 鼠标键盘
# -*- coding:utf-8 -*- ''' @project: web学习 @author: Jimmy @file: 鼠标操作.py @ide: PyCharm Community Edi ...
- [译]13-spring 内部bean
spring基于xml配置元数据的方式下,位于property元素或者contructor-arg元素内的bean元素被称为内部bean,如下: <?xml version="1.0& ...