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 ...
随机推荐
- python基础之正则表达式爬虫应用,configparser模块和subprocess模块
正则表达式爬虫应用(校花网) 1 import requests 2 import re 3 import json 4 #定义函数返回网页的字符串信息 5 def getPage_str(url): ...
- 关于学习less后一些感悟
学习了一天的less发现,自己被自己弄的晕头转向,好在是学明白了! 一.写自己的第一个less css样式编程: 网址:http://www.1024i.com/demo/less/document. ...
- Python logging 模块简介
Table of Contents 1. Logging 模块 1.1. 简介 1.2. 简单输出日志 1.3. 输入日志到文件 1.4. 几个基本概念 1.4.1. loggers 1.4.2. h ...
- Sql Server多种分页性能的比较
一.前言 因为工作关系,遇到了非常大的数据量的分页问题,数据总共有8000万吧,这个显然不是简单的分页能够解决的,需要从多多方面考虑,从分表.分库等等.但是这个也让我考虑到了分页性能的问题,在不同数据 ...
- RSA前端加密解密
技术交流群: 233513714 <html> <head> <title>JavaScript RSA Encryption</title> < ...
- spring boot 入门1-----如何使用@Value注解读取配置文件以及使用@ConfigrationProperties注解
读取.yml文件属性值的方式 1)如何将配置文件中的属性值与字段匹配起来 @Value("${配置文件中属性的名}") 在application.yml文件中 server: po ...
- Erlang中常用的类型转换[转]
转自: http://blog.sina.com.cn/s/blog_53a5047b01018yqv.html 例子 结果 atom_to_list(hello). "hello" ...
- 《Cracking the Coding Interview》——第5章:位操作——题目4
2014-03-19 06:15 题目:解释(n & (n - 1)) == 0是什么意思? 解法:n&n-1是去掉最低位‘1’的方法.根据运算符优先级,貌似用不着加那个括号,但位运算 ...
- python学习笔记八:文件与目录
一.文件的打开和创建 1.打开 open(file,mode): >>>fo = open('test.txt', 'r') >>>fo.read() 'hello ...
- 每天一个Linux命令(8):chmod命令
chmod命令用来变更文件或目录的权限. 权限范围的表示法如下: u User,即文件或目录的拥有者:g Group,即文件或目录的所属群组:o Other,除了文件或目录拥有者或所属群组之 ...