博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++ socket 客户端库 socks5 客户端 RudeSocket™ Open Source C++ Socket Library
阅读量:6162 次
发布时间:2019-06-21

本文共 6350 字,大约阅读时间需要 21 分钟。

介绍

一个c++ socket 客户端库

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 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)
  • 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. ()

 

用法

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
() 
          Constructor
() 
          Destructor

 

Method Summary
 bool () 
          Closes the connection
 bool ( const char* server, int port ) 
          Connects to the specified server and port
 bool ( const char* server, int port ) 
          Connects to the specified server and port over a secure connection
 const char* () 
          Returns a description of the last known error
 bool ( const char* server, int port ) 
          Inserts a CONNECT-Enabled HTTP proxy into the connect chain
 bool ( const char* server, int port, const char* username ) 
          Inserts a Socks4 server into the connect chain
 bool ( const char* server, int port, const char* username, const char* password ) 
          Inserts a Socks5 server into the connect chain
 bool ( const char* server, int port ) 
          Inserts a transparent tunnel into the connect chain
 int ( char* buffer, int length ) 
          Reads a buffer of data from the connection
 const char* () 
          Reads a line from the connection
 const char* () 
          Reads everything available from the connection
 int ( const char* data, int length ) 
          Sends a buffer of data over the connection
 bool ( const char* buffer ) 
          Sends a null terminated string over the connection
 void ( std::ostream& o ) 
          Sets an output stream to receive realtime messages about the socket
 void ( 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> 的代码,以防止重写义的问题

转载地址:http://dsefa.baihongyu.com/

你可能感兴趣的文章
【论文阅读】Classification of breast cancer histology images using transfer learning
查看>>
移动端处理图片懒加载
查看>>
jQuery.on() 函数详解
查看>>
谈缓存和Redis
查看>>
【转】百度地图api,根据多点注标坐标范围计算地图缩放级别zoom自适应地图
查看>>
用户调研(补)
查看>>
ExtJS之开篇:我来了
查看>>
☆1018
查看>>
oracle 去掉空格
查看>>
6.13心得
查看>>
Runtime类
查看>>
eclipse decompiler
查看>>
记一个搜索网盘资源的网站
查看>>
jdk1.7和jdk1.8的String的getByte方法的差异
查看>>
java父子进程通信
查看>>
Android ADB server didn't ACK * failed to start daemon * 简单有效的解决方案
查看>>
Olap学习笔记
查看>>
Codeforces Round #431 (Div. 1)
查看>>
如何进行数组去重
查看>>
将标题空格替换为 '_' , 并自动复制到剪切板上
查看>>