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

时间: 2024-10-25 20:01:21

c++ socket 客户端库 socks5 客户端 RudeSocket? Open Source C++ Socket Library的相关文章

c++下基于windows socket的单线程服务器客户端程序

今天自己用编写了一个简单的c++服务器客户端程序,注释较详细,在此做个笔记. windows下socket编程的主要流程可概括如下:初始化ws2_32.dll动态库-->创建套接字-->绑定地址信息-->服务器进行监听/客户端连接服务器-->数据交换-->关闭套接字对象. 服务器端: 1 #include <Winsock2.h> 2 #include <Ws2tcpip.h> 3 #include <iostream> 4 5 #prag

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

上一篇FTP客户端讲到如果制作一个简单的FTP客户端,功能实现了,但是后面我们发现了问题,就是FTP是使用明文进行操作的.对于普通情况来说就无所谓了.但有时候要安全的一点的话,就应该使用FTP的安全版本.有SFTP和FTPs,两者都是FTP的安全版本,但是两者的实现原理差别还是很大的,具体自己搜索了解. 0.环境安装 环境使用我的这一篇文章安装好libssh2库. http://www.cnblogs.com/wunaozai/p/4528394.html 使用一个带有SFTP功能的FTP服务器

猿题库 iOS 客户端架构设计(原文地址:http://gracelancy.com/blog/2016/01/06/ape-ios-arch-design/)

猿题库 iOS 客户端架构设计 序 猿题库是一个拥有数千万用户的创业公司,从2013年题库项目起步到2015年,团队保持了极高的生产效率,使我们的产品完成了五个大版本和数十个小版本的高速迭代.在如此快速的开发过程中,如何保证代码的质量,降低后期维护的成本,以及为项目越来越快的版本迭代速度提供支持,成为了我们关注的重要问题.这篇文章将阐明我们在猿题库 iOS 客户端的架构设计. MVC MVC,Model-View-Controller,我们从这个古老而经典的设计模式入手.采用 MVC 这个架构的

socket系列之socket服务端与客户端如何通信

上面已经分别介绍了ServerSocket跟Socket的工作步骤,并且从应用层往系统底层剖析其运作原理,我们清楚了他们各自的一块,现在我们将把他们结合起来,看看他们是如何通信的,并详细讨论一下他们之间相互通信的一些细节. 借助图2-3-2-4,想象一下你正在大学课室上着电脑,你跟你另外两个朋友觉得老师讲得课很菜,没必要听,于是你们仨都各自打开浏览器冲浪,刚好你们访问了同一台服务器,假如你用的是浏览器A,那么整个流程为: ① 浏览器确认目标IP跟目标端口号(http默认使用80端口),当然如果你

使用Socket通信实现Silverlight客户端实时数据的获取(模拟GPS数据,地图实时位置)

原文:使用Socket通信实现Silverlight客户端实时数据的获取(模拟GPS数据,地图实时位置) 在上一篇中说到了Silverlight下的Socket通信,在最后的时候说到本篇将会结合地图.下面就来看看本文实现的功能: Silverlight 与服务器利用Socket通讯,实时从服务器获取数据(本文中的数据是地理坐标),由于没有GPS,所以本文在服务器写了一个构造新坐标的函数(本文是一个三角函数),然后利用Timer组件,实时调用,得到新的坐标,并将新的坐标发送给客户端,客户端接收到发

socket服务端和客户端

#!/usr/bin/env python#encoding: utf-8import socketdef handle_request(client): buf = client.recv(1024) client.send("HTTP/1.1 200 OK\r\n\r\n") client.send("Hello, World") def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREA

尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。

从10G开始,Oracle提供了一个较为轻量级的客户包,叫做Instant Client. 将它安装好后,就不用再安装庞大的Oracle Client了. 这样一来,只要客户端下载Instant Client,直接解压,设置Path就ok了.具体设置如下:1.下载32位Oracle InstantClient 2.将Oracle InstantClient解压到某目录 3.打开PL/SQL,在perference里面设置OCI Library和Oracle_home,例子如下:        

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

由于其他事情耽误,这个翻译现在才完成.接上篇—— 4 瘦客户端核心库架构 由于AllJoyn瘦客户端核心库(AJTCL)必须运行在那些功耗受限.计算能力有限.资源紧缺的设备上,因此它无法像运行在通用型计算机系统上那样使用和AllJoyn标准核心库(AJSCL)一样的架构. 一个AJSL或服务进程的分层结构如图3所示.<Introduction to the AllJoyn Framework>一文描述了这些层次结构的更详尽细节.需要特别注意的是, 每个Alljoyn客户端或服务器程序都会以这种

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

Alljoyn瘦客户端库介绍(1) 1.简介 本文档对AllJoynTM瘦客户端的核心库文件(AJTCL)进行了详尽的介绍.本文档介绍了系统整体架构,AllJoyn框架结构,并着重于介绍如何将嵌入式设备加入AllJoyn系统整体架构中.1.1目的 本文档介绍了如何使一个受限于功耗.计算能力和内存的设备(嵌入式设备)加入AllJoyn分布式系统.具体而言,本文档包括了对AllJoyn面向嵌入式系统的方面的介绍,并着重描述了基于AllJoyn的系统的各个组件是如何与嵌入式设备协作以构建一个基于接近式