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.

介绍

一个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> 的代码,以防止重写义的问题

相关文章
|
5月前
|
网络协议 PHP
Swoole 源码分析之 TCP Server 模块
从 Swoole 官网的这段短小精悍的代码,就可以看出 Server 服务的关键要点。再通过对类、构造方法、回调函数的层层剖析,我们逐渐的了解了底层的实现原理。
67 8
Swoole 源码分析之 TCP Server 模块
|
3月前
|
SQL 安全 Java
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
434 0
|
6月前
|
运维 网络安全 Python
使用Python http.server模块共享文件
今天给大家介绍一下Python标准库中的http.server模块。这个模块提供了一种简单的方式来快速启动一个HTTP服务器,非常适合临时共享文件、测试、教学等轻量级场景。
|
6月前
|
网络协议
Qt Tcp Server
Qt Tcp Server
41 0
OPC Server与YFIOServer成功绑定
花了几天的时间,终于读懂了老唐的OPC Server代码,把XML相关的内容全部去掉,取而代之的是YFIOServer的相关接口,可以把YFIOServer中配置的内容变量自动发布出去,这样结合马上就有了PPI OPC服务器,Modbus OPC服务器
834 0
|
网络协议 关系型数据库 Linux
PostgreSQL pgsocket: Extension for Simple TCP/IP Socket Client
标签 PostgreSQL , pgsocket 背景 PostgreSQL 插件,向外部tpc/ip socket服务发生字节流。 pgsocket is an extension for PostgreSQL server to send bytes to remote TCP/IP socket server.
859 0
|
移动开发 网络协议 开发工具
[网络篇]ESP8266-SDK教程(三)之TCP通信Server<->Client
纳尼?昨天刚刚打印了个“Hello World!”,今天你就让我学习TCP通信?有没有搞错~哈哈,相信很多读者会很迷,其实学习这东西嘛,单单学一些比较简单的,相信没两天就没人看了,所以咱就在基础篇和网络篇穿插着去学习一下ESP8266,毕竟兴趣才是最好的老师嘛!大家以后遇到问题了,来翻文章建议大家根...
2092 0
|
Web App开发 网络协议 Windows