c++ socket 客户端库 socks5 客户端 RudeSocket™ Open Source C++ Socket Library
介绍
一个c++ socket 客户端库
http://www.rudeserver.com/socket/index.html
The RudeSocket™ Open Source C++ Socket Library provides a simple to use interface for creating and using client sockets. You can connect to the destination server through an unlimited number of chainable proxies, SOCKS4 and SOCKS5 servers if anonymity or security is a priority. Supports SSL [1] as well as normal connections. Supports timeouts. Full version requires that openSSL libraries are installed. However, a lite version is available if SSL is not required or available.
The library is currently available for linux development environments.
Features:
- SSL Support (Linux and Windows) [1]
- Supports Sockes 4, Socks 5, HTTP Proxy
- Like all RudeServer Libraries: Simple and Easy to use.
- Open Source and Free
- Platform Independent Interface
[1] - This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)
用法
General Usage
Socket *socket = new Socket();
socket->connect("google.com", 80);
socket->sends("GET / HTTP/1.0\n\n");
const char *response = socket->reads();
cout << response;
socket->close();
SSL Usage
Socket *socket = new Socket();
socket->connectSSL("google.com", 443);
socket->sends("GET / HTTP/1.0\n\n");
const char *response = socket->reads();
cout << response;
socket->close();
Chaining Connections
Socket *socket = new Socket();
socket->insertSocks4("12.34.56.78", 8000, "username");
socket->insertSocks5("12.34.56.78", 8000, "username", "password");
socket->insertProxy("12.34.56.78", 8080);
socket->connectSSL("google.com", 443);
socket->sends("GET / HTTP/1.0\n\n");
const char *response = socket->reads();
cout << response;
socket->close();
Adding Error checking
Socket *socket = new Socket();
if(socket->connectSSL("google.com", 443))
{
if(socket->sends("GET / HTTP/1.0\n\n"))
{
const char *response = socket->reads();
if(response)
{
cout << response;
}
else
{
cout << socket->getError() << "\n";
}
}
else
{
cout << socket->getError() << "\n";
}
socket->close();
}
else
{
cout << socket->getError() << "\n";
}
Constructor Summary | |
Socket() Constructor |
|
~Socket() Destructor |
Method Summary | |
bool |
close() Closes the connection |
bool |
connect( const char* server, int port ) Connects to the specified server and port |
bool |
connectSSL( const char* server, int port ) Connects to the specified server and port over a secure connection |
const char* |
getError() Returns a description of the last known error |
bool |
insertProxy( const char* server, int port ) Inserts a CONNECT-Enabled HTTP proxy into the connect chain |
bool |
insertSocks4( const char* server, int port, const char* username ) Inserts a Socks4 server into the connect chain |
bool |
insertSocks5( const char* server, int port, const char* username, const char* password ) Inserts a Socks5 server into the connect chain |
bool |
insertTunnel( const char* server, int port ) Inserts a transparent tunnel into the connect chain |
int |
read( char* buffer, int length ) Reads a buffer of data from the connection |
const char* |
readline() Reads a line from the connection |
const char* |
reads() Reads everything available from the connection |
int |
send( const char* data, int length ) Sends a buffer of data over the connection |
bool |
sends( const char* buffer ) Sends a null terminated string over the connection |
void |
setMessageStream( std::ostream& o ) Sets an output stream to receive realtime messages about the socket |
void |
setTimeout( int seconds, int microseconds ) Sets the timeout value for Connect, Read and Send operations. |
Constructor Detail |
Socket
public Socket();
- Constructor
~Socket
public ~Socket();
- Destructor
Method Detail |
close
public bool close();
- Closes the connection
A connection must established before this method can be called
connect
public bool connect( const char* server, int port );
- Connects to the specified server and port
If proxies have been specified, the connection passes through tem first.
connectSSL
public bool connectSSL( const char* server, int port );
- Connects to the specified server and port over a secure connection
If proxies have been specified, the connection passes through them first.
getError
public const char* getError();
- Returns a description of the last known error
insertProxy
public bool insertProxy( const char* server, int port );
- Inserts a CONNECT-Enabled HTTP proxy into the connect chain
Becomes the last server connected to in the chain before connecting to the destination server
insertSocks4
public bool insertSocks4( const char* server, int port, const char* username );
- Inserts a Socks4 server into the connect chain
Becomes the last server connected to in the chain before connecting to the destination server
insertSocks5
public bool insertSocks5( const char* server, int port, const char* username, const char* password );
- Inserts a Socks5 server into the connect chain
Becomes the last server connected to in the chain before connecting to the destination server
insertTunnel
public bool insertTunnel( const char* server, int port );
- Inserts a transparent tunnel into the connect chain
A transparent Tunnel is a server that accepts a connection on a certain port,
and always connects to a particular server:port address on the other side.
Becomes the last server connected to in the chain before connecting to the destination server
read
public int read( char* buffer, int length );
- Reads a buffer of data from the connection
A connection must established before this method can be called
readline
public const char* readline();
- Reads a line from the connection
A connection must established before this method can be called
reads
public const char* reads();
- Reads everything available from the connection
A connection must established before this method can be called
send
public int send( const char* data, int length );
- Sends a buffer of data over the connection
A connection must established before this method can be called
sends
public bool sends( const char* buffer );
- Sends a null terminated string over the connection
The string can contain its own newline characters.
Returns false and sets the error message if it fails to send the line.
A connection must established before this method can be called
setMessageStream
public void setMessageStream( std::ostream& o );
- Sets an output stream to receive realtime messages about the socket
setTimeout
public void setTimeout( int seconds, int microseconds );
- Sets the timeout value for Connect, Read and Send operations.
Setting the timeout to 0 removes the timeout - making the Socket blocking.
编译:
官方原版源码下载:点击下载
删除socket_platform.h文件包含 #include <winsock2.h> 的代码,以防止重写义的问题
c++ socket 客户端库 socks5 客户端 RudeSocket™ Open Source C++ Socket Library的更多相关文章
- Socket网络编程--FTP客户端
Socket网络编程--FTP客户端(1)(Windows) 已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解F ...
- Socket网络编程--FTP客户端(1)(Windows)
已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解FTP作用 就是一个提供一个文件的共享协议. 1.了解FTP协议 ...
- Socket网络编程--FTP客户端(60篇socket博客,而且都比较简单、深入浅出)
已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解FTP作用 就是一个提供一个文件的共享协议. 1.了解FTP协议 ...
- Redis学习之路(008)- Redis C语言客户端库hiredis文档翻译
Hiredis是Redis数据库一个轻量的C语言客户端库. 之所以轻量是由于它只是简单的提供了对redis操作语句支持的接口,并没有实现具体的操作语句的功能.但正是由于这种设计使我们只要熟悉了通用的r ...
- c++下基于windows socket的单线程服务器客户端程序(基于TCP协议)
今天自己编写了一个简单的c++服务器客户端程序,注释较详细,在此做个笔记. windows下socket编程的主要流程可概括如下:初始化ws2_32.dll动态库-->创建套接字-->绑定 ...
- 计算机网络:套接字(Socket)| Python socket实现服务器端与客户端通信,使用TCP socket阿里云ECS服务器与本机通信
所谓套接字(Socket),就是对网络中不同主机上的应用进程之间进行双向通信的端点的抽象.一个套接字就是网络上进程通信的一端,提供了应用层进程利用网络协议交换数据的机制.从所处的地位来讲,套接字上联应 ...
- Alljoyn瘦客户端库介绍(官方文档翻译 下)
由于其他事情耽误,这个翻译现在才完成.接上篇—— 4 瘦客户端核心库架构 由于AllJoyn瘦客户端核心库(AJTCL)必须运行在那些功耗受限.计算能力有限.资源紧缺的设备上,因此它无法像运行在通用型 ...
- Alljoyn瘦客户端库介绍(官方文档翻译)
Alljoyn瘦客户端库介绍(上) 1.简介 本文档对AllJoynTM瘦客户端的核心库文件(AJTCL)进行了详尽的介绍.本文档介绍了系统整体架构,AllJoyn框架结构,并着重于介绍如何将嵌入式设 ...
- 尝试加载 Oracle 客户端库时引发 BadImageFormatException
尝试加载 Oracle 客户端库时引发 BadImageFormatException 工程师给计算机诊断,就像医生给病人诊断一样,很多同样的症状,可能是由多种截然不同的原因导致的. 最近进行C# ...
随机推荐
- LDA-math-文本建模
http://cos.name/2013/03/lda-math-text-modeling/ 4. 文本建模 我们日常生活中总是产生大量的文本,如果每一个文本存储为一篇文档,那每篇文档从人的观察来说 ...
- zw·准专利·高保真二值图细部切分算法
zw·准专利·高保真二值图细部切分算法 高保真二值图细部切分算法,是中国字体协会项目的衍生作品. 说准专利算法,是因为对于图像算法的标准不了解,虽然报过专利,但不是这方面的,需要咨询专 ...
- wireshark抓包
ip.addr==IP地址(192.168.1.100)&& http
- hadoop文件系统FileSystem详解 转自http://hi.baidu.com/270460591/item/0efacd8accb7a1d7ef083d05
Hadoop文件系统 基本的文件系统命令操作, 通过hadoop fs -help可以获取所有的命令的详细帮助文件. Java抽象类org.apache.hadoop.fs.FileSystem定义了 ...
- Android扫描文件
扫描文件及文件夹 package com.bwie.demo; import java.io.File; import java.io.FileFilter; import java.util.Arr ...
- 慎用MySQL replace语句
语法: REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [PARTITION (partition_name,...)] [(col_name,... ...
- Content Delivery Network
Coding Standards & Best Practices 7 Reasons to use a Content Delivery Network CDN公共库汇总
- jq 动态判断设备添加对应meta viewport属性内同
1.常见的单位 dip, dp, px, sp之间的区别: dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支 ...
- 【转载】PostgreSQL分区表(Table Partitioning)应用
博客地址--点击
- C/C++的一些备忘
今天使用source insight阅读videoserver源码,有一些符号ctrl+左键点击显示找不到,先是rebuild工程和同步,没有效果,然后Options->Preferences- ...