介绍

一个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的更多相关文章

  1. Socket网络编程--FTP客户端

    Socket网络编程--FTP客户端(1)(Windows) 已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解F ...

  2. Socket网络编程--FTP客户端(1)(Windows)

    已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解FTP作用 就是一个提供一个文件的共享协议. 1.了解FTP协议 ...

  3. Socket网络编程--FTP客户端(60篇socket博客,而且都比较简单、深入浅出)

    已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解FTP作用 就是一个提供一个文件的共享协议. 1.了解FTP协议 ...

  4. Redis学习之路(008)- Redis C语言客户端库hiredis文档翻译

    Hiredis是Redis数据库一个轻量的C语言客户端库. 之所以轻量是由于它只是简单的提供了对redis操作语句支持的接口,并没有实现具体的操作语句的功能.但正是由于这种设计使我们只要熟悉了通用的r ...

  5. c++下基于windows socket的单线程服务器客户端程序(基于TCP协议)

    今天自己编写了一个简单的c++服务器客户端程序,注释较详细,在此做个笔记. windows下socket编程的主要流程可概括如下:初始化ws2_32.dll动态库-->创建套接字-->绑定 ...

  6. 计算机网络:套接字(Socket)| Python socket实现服务器端与客户端通信,使用TCP socket阿里云ECS服务器与本机通信

    所谓套接字(Socket),就是对网络中不同主机上的应用进程之间进行双向通信的端点的抽象.一个套接字就是网络上进程通信的一端,提供了应用层进程利用网络协议交换数据的机制.从所处的地位来讲,套接字上联应 ...

  7. Alljoyn瘦客户端库介绍(官方文档翻译 下)

    由于其他事情耽误,这个翻译现在才完成.接上篇—— 4 瘦客户端核心库架构 由于AllJoyn瘦客户端核心库(AJTCL)必须运行在那些功耗受限.计算能力有限.资源紧缺的设备上,因此它无法像运行在通用型 ...

  8. Alljoyn瘦客户端库介绍(官方文档翻译)

    Alljoyn瘦客户端库介绍(上) 1.简介 本文档对AllJoynTM瘦客户端的核心库文件(AJTCL)进行了详尽的介绍.本文档介绍了系统整体架构,AllJoyn框架结构,并着重于介绍如何将嵌入式设 ...

  9. 尝试加载 Oracle 客户端库时引发 BadImageFormatException

    尝试加载 Oracle 客户端库时引发 BadImageFormatException 工程师给计算机诊断,就像医生给病人诊断一样,很多同样的症状,可能是由多种截然不同的原因导致的.   最近进行C# ...

随机推荐

  1. 为archlinux配置cron

    cron的作用:cron可以用来周期性地自动执行一些命令. cron的实现:cron有很多实现版本,例如:cronie, dcron, fcron, bcron, vixie-cron,我安装的是 c ...

  2. Java高效编程之二【对所有对象都通用的方法】

    对于所有对象都通用的方法,即Object类的所有非final方法(equals.hashCode.toString.clone和finalize)都有明确的通用约定,都是为了要被改写(override ...

  3. phabricator

    (1)安装./bitnami-phabricator-20160523-0-linux-x64-installer.run (2)中文phabricator-zh_CN.tar解压缩到/opt/pha ...

  4. Spring事务注解@Transactional回滚问题

    Spring配置文件,声明事务时,如果rollback-for属性没有指定异常或者默认不写:经测试事务只回滚运行时异常(RuntimeException)和错误(Error). <!-- 配置事 ...

  5. java中的单例设计模式

    单例模式有一下特点: 1.单例类只能有一个实例. 2.单例类必须自己自己创建自己的唯一实例. 3.单例类必须给所有其他对象提供这一实例. 单例模式确保某个类只有一个实例,而且自行实例化并向整个系统提供 ...

  6. jQuery中attr() 和 prop()【转】

    Version 1.9.0 开始不建议使用 attr() 来对具有 true 和 false 两个属性的属性进行操作. 具有 true 和 false 两个属性的属性,如 checked, selec ...

  7. Hibernate,JPA注解@SecondaryTables

    使用类一级的 @SecondaryTable或@SecondaryTables注解可以实现单个实体到多个表的映射. 使用 @Column或者 @JoinColumn注解中的table参数可指定某个列所 ...

  8. iOS中 项目开发易错知识点总结

    点击return取消textView 的响应者 - (BOOL)textFieldShouldReturn:(UITextField *)textField { [_contactTextFiled  ...

  9. Java中Synchronized的用法

    原文:http://blog.csdn.net/luoweifu/article/details/46613015 作者:luoweifu 转载请标名出处 <编程思想之多线程与多进程(1)——以 ...

  10. yjfk 意见反馈

    <div> <h1>我的第一个 JavaScript 程序</h1><p id="demo">这是一个段落</p>< ...