linux socket 开源库,libsocket

2023-11-16

README for libsocket

afc359b03a62ff194fe60d0691f63514.png

BUILDING libsocket

If you want to install both libsocket and libsocket++, simply use this command:

$ mkdir build && cd build

$ cmake ..

$ make # or make install

This installs the SOs libsocket.so and libsocket++.so to /usr/lib/ and the header files to

/usr/include/libsocket. You may change these paths in the CMakeLists.txt file in the project root.

Note the changed library name on SunOS, where it is called libsocket_hl (for "high level").

CMake is required to support object libraries, which is the case in versions higher than or equal to

2.8.

WHAT IS libsocket AND WHY SHOULD I USE IT?

libsocket is a library with a C part and a C++ part making sockets usage easy and clean.

Link against libsocket.so

Functions combining more than one operation on sockets (e.g. create and connect TCP socket)

Main principle: "One function to connect a socket, one to close it."

Link against libsocket++.so

Classes representing the different socket types, e.g. TCP client sockets, UNIX DGRAM "server"

sockets.

Complex (almost complicated...) class hierarchy (doc/libsocket++/classes.svg) reducing

duplication.

C++ish implementation (features include overloaded stream (<>) operators, functions

accepting std::string objects and more-or-less STL use), so -> good integration in other

applications or libraries.

Using C++11 features: The copy constructor of the socket base class is deleted; this enables the

destructor to safely close the socket when it leaves the visible scope. Some functions are

internally using unique_ptrs to enable safe deallocation.

FEATURES AND ADVANTAGES

The libsocket library has the following features:

IPv4 (client, server)

IPv6 (client, server; if your machine supports it)

TCP (client, server)

UDP (client, server -- the difference is that client sockets may be connected to an endpoint)

UNIX Domain Sockets (DGRAM/STREAM server/client)

IPv4/IPv6 multicast (only in C)

Abstraction classes for select(2) and epoll(7) (C++)

Easy use (one function call to get a socket up and running, another one to close it)

RAII, no-copy classes -- resource leaks are hard to do.

Proper error processing (using errno, gai_strerror() etc.) and C++ exceptions.

One of the main advantages of libsocket is that you don't have to write the complex and error-prone

procedures for connecting a socket, checking it for errors etc. yourself. Your networked programs

become shorter and better readable.

libsocket supports the important socket types: INET/INET6 with TCP and UDP; and UNIX DGRAM/STREAM.

Almost every function working with sockets is wrapped by libsocket, e.g.:

sendto

recvfrom

accept

socket/connect - one function

socket/bind - one function

libsocket is designed to not use a "proprietary" socket format (as libc does with its FILE type)

giving you the possibility to operate on the raw file descriptor with functions other than those

provided by libsocket.

PLATFORMS

Please let me know if a platform is not supported as well as it should, or if you managed to port

libsocket to a new platform.

GNU/Linux

Libsocket works best on modern linux systems (sorry!). It needs a C++11 compiler like g++ or

clang++. Override the default compiler using the flag -DCMAKE_CXX_COMPILER= or

-DCMAKE_C_COMPILER=.

FreeBSD

Other than on Linux systems libsocket is known to work as well (although not really thoroughly

tested) on FreeBSD systems with working C++11 stack. The library has been tested on a

FreeBSD 10.0-RC4 amd64 system using the shipped compilers (which is clang 3.3).

SunOS: OpenIndiana, (Solaris?)

The library part written in C works (partly) also on OpenIndiana; this has been verified using

SunOS openindiana 5.11 oi_151a8.

Because a modern C++ compiler was not available at the time of testing, the C++ library part is not

built on SunOS systems.

Another hurdle is that Solaris already ships with a libsocket containing the standard socket

functions. The C library is thus renamed to libsocket_hl on SunOS. You have to link your programs

using the flag -lsocket_hl, not -lsocket.

SunOS limitations

The UDP server example (examples/echo_dgram_server.c) refuses to create a socket. The error is

"Operation not supported on transport endpoint".

The TCP server example (examples/transmission_server.c) also fails when trying to create the

socket. Here, the error displayed is "Invalid argument". I'm quite sure that these issues can be

fixed with a little investigation and knowledge of SunOS.

OpenBSD

libsocket does not work on OpenBSD yet because there are some more fundamental source

level incompatibilities than those between Linux and FreeBSD/OpenIndiana-SunOS.

Other OSs

If you're using libsocket successfully on other platforms (or even ported it), please

let me know.

How to use libsocket: static vs. dynamic

Linking statically

It's possible to link libsocket statically into your program (by placing the .c[pp] and .h[pp] files

in your source tree or linking against a .a file). You don't have to mind legal issues

because libsocket is licensed by a slightly modified 2-clause BSD license which permits any use, as

long as you include the license text in your product (so it's clear that libsocket is licensed by

this License) and the notice that we wrote libsocket (as described in the license). It's

ok to mention libsocket in your product's Readme or advertisements anyway.

Linking statically in CMake Projects

It is possible to produce static libraries for linking by setting the cmake configuration option

BUILD_STATIC_LIBS=ON. This can be done from command line or in your CMakeLists.txt.

SET(BUILD_SHARED_LIBS ON) add_subdirectory(libsocket)

target_link_libraries(MyProject libsocket_int) # C linking target_link_libraries(MyProject

libsocket++_int) # C++ linking

Please note the cmake targets for static libraries are _int, but the produced libraries

will have the expected libsocket(++).a name on disk.

Linking dynamically

The recommended method to use libsocket is to link your program against the libsocket SO (DLL).

Using this method is quite easy; you have to compile the dynamic libraries (libsocket and

libsocket++) using the Makefile (see section "BUILDING")

Linking your programs against the library is also simple: if $OBJECTS are your object files, then

link them together using one of these commands:

$ gcc -o yourprog -lsocket $OBJECTS

# or for C++

$ g++ -o yourprog -lsocket++ $OBJECTS

You only need to link against one library, even when using C++, because libsocket++ is already

linked against libsocket.

If you distribute your program in binary form, it's possible to distribute the library binaries

along with your program and install them along your program.

EXAMPLES

You may test libsocket and make some experiences by playing with the examples provided in the

standard libsocket distribution in examples/ and examples++. More detailed descriptions can be found

in the source files. The collection of examples contain (among others):

(C)

http.c: A simple http client

echo_dgram_server.c, echo_dgram_client.c, echo_dgram_connect_client.c: Shows how to use UDP

sockets, both in connected and unconnected mode.

unix_stream_client.c, unix_stream_server.c: Demonstrating UNIX STREAM sockets as echo

server/client

unix_dgram_client.c, unix_dgram_server.c: Demonstrating UNIX DGRAM sockets as simple

server/client transmitting text.

multicast-listen.c: Demonstrating how to use libinetsocket for multicast networking.

Build these with gcc -o -lsocket .

(C++)

http.cpp, http_2.cpp: Two simple HTTP clients using slightly different approaches

server.cpp, client.cpp: TCP client and server

unix_client_dgram.cpp: Writes a message to the syslog using UNIX DGRAM sockets

echo_server.cpp, echo_client_conn.cpp, echo_client_sndto.cpp: UDP client/server (two clients:

One using sendto(), another using connected datagram sockets)

unix_client_stream.cpp, unix_server_stream.cpp: Client/Server using UNIX STREAM sockets.

Build these with [clan]g++ -std=c++11 -lsocket++ -o .

You should have a look at the length of the code; while http.c is complete with 24 sloc (source

lines of code) - the quite similar client simple-http

(https://github.com/dermesser/Simple-HTTP-client) uses almost 70 lines of code.

TODO

Currently nothing! libsocket is not actively developed, as it is mostly feature complete, but it

is actively maintained.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

linux socket 开源库,libsocket 的相关文章

  • QML使用loader加载qml文件到QML

    转自 http blog chinaunix net uid 26126915 id 4366840 html QML的Loader元素经常备用来动态加载QML组件 可以使用source属性或者sourceComponent属性加载 这个元
  • 跨vlan通信-----单臂路由技术

    跨vlan通信 单臂路由技术 实验目标 1 实现跨vlan通信 为什么要使用vlan 1 提高性能 同一个广播域发送广播 造成网络堵塞 2 提高安全性 同一广播域中 机器设备过多 安全性降低 实验网络拓扑 pc1 pc2 pc3 pc4 V
  • Elastic Stack简介及es简单操作

    如果你没有听说过 Elastic Stack 那你一定听说过 ELK 实际上 ELK 是三款软件的简称 分别是 Elasticsearch Logstash Kibana 组成 在发展的过程中 又有新成员 Beats 的加入 所以就形成了
  • M2后日谈

    团队成员的简介 按照字母表序 韩佳胤 http www cnblogs com yinee 黄杨 http www cnblogs com skyjoker 林璐 http www cnblogs com linlu1142 刘俊伟 htt
  • 206.Flink(一):flink概述,flink集群搭建,flink中执行任务,单节点、yarn运行模式,三种部署模式的具体实现

    一 Flink概述 1 基本描述 Flink官网地址 Apache Flink Stateful Computations over Data Streams Apache Flink Flink是一个框架和分布式处理引擎 用于对无界和有界
  • Servlet--会话管理

    默认情况下 一个Web服务器是无法区分一个HTTP请求是否为第一次访问 例如 一个Web邮件应用要求用户登录后才能查看邮件 因此 当用户输入了相应的用户名和密码后 应用不应该再次提示需要用户登录 应用必须记住哪些用户已经登录 即应用必须能管
  • 蓝桥杯 模拟赛 D快速幂

    一个数的整数次幂 是我们在计算中经常用到的 但是怎么可以在 mathcal O log n O log n 的时间内算出结果呢 代码框中的代码是一种实现 请分析并填写缺失的代码 求 x y mod pxymodp 的结果 include
  • c++之 继承、 多态

    目录 继承 1继承的概念及定义 总结 基类和派生类对象赋值转换 继承中的作用域 派生类的默认成员函数 继承与友元 与静态成员 复杂的菱形继承及菱形虚拟继承 多态 多态的概念 虚函数重写的两个例外 重载 覆盖 重写 隐藏 重定义 的对比 抽象
  • JAVA中string按照之前顺序转换JSONObject

    可以使用LinkedHashMap来保持JSONObject中的键值对的顺序 首先 将JSON字符串转换为LinkedHashMap 然后将其转换为JSONObject 代码如下 import com alibaba fastjson JS
  • 计算机二级复习之文件操作

    博主正在准备考二级C语言但是最怕的就是遇到文件操作相关的题 真的是太难了 为了那些和我一起考二级的小伙伴我更新这期C语言文件操作的相关资料 文件的打开与关闭 在打开文件之前我们需要先创建一个文件指针 FILE fp 用来记录地址 文件打开函
  • 源码安装Tomcat及配置

    8005 是tomcat本身的端口 8080 tomcat负责建立HTTP连接 在通过浏览器访问Tomcat服务器的Web应用时 使用 8009 tomcat负责和其他的HTTP服务器建立连接 如nginx和apache互通时使用 tomc
  • 常用中间件启动脚本

    ActiveMQ bin bash description activemq ACTIVEMQ PATH usr local activemq export JAVA HOME usr java jdk1 8 0 241 amd64 cas
  • MySQL字段类型详解

    http www chinaz com program 2009 0105 59154 shtml MySQL支持大量的列类型 它可以被分为3类 数字类型 日期和时间类型以及字符串 字符 类型 本节首先给出可用类型的一个概述 并且总结每个列
  • 联盟链战国:五大巨头横向对比

    联盟链是目前区块链落地实践的热点 也是大家对 杀手级应用 期望最大的区块链部署形态 联盟链的诞生源于对区块链技术的 反思 是对比特币 以太坊所体现的技术特点与企业客户实际需要的融合与折衷 蕴含了大量区块链工作者的智慧与辛劳 由于对未来价值的
  • Node.js

    修改软件安装的路径 此电脑右击 属性 高级系统设置 环境变量 选中path 编辑 修改路径 确定 定义区别 一 浏览器中的JS 1 浏览器中的JS组成 JS核心语法 ECMAScript 和 WebAPI 浏览器内置的API 2 为什么Ja
  • 在cms以及kindeditor中插入百度动态地图的方法

    想在网页中插入动态地图不难 直接打开网址http api map baidu com lbsapi creatmap 然后按照提示操作 最终生成脚本 放到html文件中即可 而在kindeditor中插入动态地图就更简单了 最新版的kind
  • 部分和问题(c/c++)

    给定整数a1 a2 a3 an 判断是否可以从中 选出若干输使得它们的和恰好为k 第一行输入n代表几个数字 第二行输入数字 第三行输入结果 样例 4 1 2 4 7 13 yes 这是一道基础题 对于初学者而言使用两重循环无疑是最便捷的 i
  • 路由器与交换机的基本工作原理

    本文介绍路由器与交换机的基本工作原理 在介绍这之前先来看一下OSI七层工作模型 现在开始解释路由器的作用及其基本工作原理 路由器的作用 1 异种网络互连 比如具有异种子网协议的网络互连 2 子网协议转换 不同子网间包括局域网和广域网之间的协
  • 论文排版:Word加入脚注后,分栏的正文就跑到下一页上去了的解决方案

    在论文排版中 在题目或作者处插入了脚注后 再对正文分栏时 或者先分栏 再在题目或作者处插入脚注 分栏后的正文就跑到下一页上去了 这个问题 我抓狂了很久 终于在搜索若干关键字后得以解决 情况一 稿件格式的要求 1 题目和摘要部分不分栏 正文部

随机推荐

  • 【架构】1.2浅谈架构基础-架构设计的目的

    架构设计的目的 架构设计的目的 软件发展历程 如何识别软件的复杂度 高性能 高可用 可扩展 成本价值 安全因素 架构设计的目的 谈及架构设计 应该IT从业者都很经常听到 然而对于架构设计的目的 可能每个人都有自己的理解 例如 因为现在的系统
  • 毕业设计 opencv图像增强算法系统

    文章目录 0 简介 1 基于直方图均衡化的图像增强 2 基于拉普拉斯算子的图像增强 4 基于伽马变换的图像增强 软件实现效果 最后 0 简介 今天学长向大家分享一个毕业设计项目 毕业设计 opencv图像增强算法系统 项目运行效果 毕业设计
  • 8个不可不知的Mac OS X专用命令行工具

    本文转载至 https segmentfault com a 1190000000509514 OS X的终端下通用很多Unix的工具和脚本 如果从Linux迁移到OS X会发现很多熟悉的命令和脚本工具 其实并没有任何区别 但是OS X也提
  • Clamav杀毒软件源码分析笔记[十]

    Clamav杀毒软件源码分析笔记 十 刺猬 http blog csdn net littlehedgehog 客户端处理 服务端已经把主要的工作都已经处理的差不多了 剩下来也就是服务端等待客户端提出请求 然后根据客户端的请求做相应的工作
  • sql注入绕过技巧

    前言 今天斗胆来整理一下sql注入的各种绕过姿势 以后方便查阅 SQL注入的绕过技巧有很多 具体的绕过技巧需要看具体的环境 而且很多的绕过方法需要有一个实际的环境 最好是你在渗透测试的过程中遇到的环境 否则如果仅仅是自己凭空想 那显然是不靠
  • C语言项目——学生信息管理系统

    文章目录 学生信息管理系统 一 项目思路 1 模块化思想 2 流程图 二 功能框架 1 系统菜单 2 其他功能 三 分布实现 0 学生属性 系统属性 1 学生属性 2 系统属性 1 创建系统 2 绘制菜单 3 按键操作 4 录入信息 5 浏
  • 等精度测频原理--频率计

    等精度测频原理 频率计 本系统采用等精度测频的原理来测量频率 其原理如图2所示 图2 等精度测频原理图 图2中的门控信号是可预置的宽度为Tpr的一个脉冲 CNT1和CNT2是两个可控计数器 标准频率信号从CNT1的时钟输入端FS输入 其频率
  • 常见的几种矩阵分解方式

    项目github地址 bitcarmanlee easy algorithm interview and practice 欢迎大家star 留言 一起学习进步 1 三角分解 LU分解 矩阵的LU分解是将一个矩阵分解为一个下三角矩阵与上三角
  • H5浏览器播放RTMP直播流

  • Python编程快速上手

    题目1 编写一个名为collatz 的函数 它有一个名为number的参数 如果参数是偶数 那么collatz 就打印出number 2 如果number是奇数 collatz 就打印3 number 1 def collatz numbe
  • 面试题 ⑥

    1 Java常见的线程池有哪些 它们的使用场景 newSingleThreadExecutor 创建一个单线程的线程池 此线程池保证所有的执行顺序按照任务的提交顺序执行 FIFO 适合顺序处理文件日志等 newFixedThreadPool
  • easyUI datagrid中checkbox选中事件以及行点击事件,翻页之后还可以选中

    DataGrid其中与选择 勾选相关 DataGrid属性 singleSelect boolean 如果为true 则只允许选择一行 false ctrlSelect boolean 在启用多行选择的时候允许使用Ctrl键 鼠标点击的方式
  • MySQL主从复制(Master-Slave)实践

    转载自 https www cnblogs com gl developer p 6170423 html 参考 https blog csdn net lildkdkdkjf article details 10004663 MySQL数
  • Python的pickle模块详解(包括优缺点及和JSON的区别)

    文章目录 一 pickle是什么 1 pickle的优缺点 2 pickle和JSON的区别 3 pickle的应用总结 二 pickle的用法 1 pickle接口 2 pickle实例 结语 一 pickle是什么 在英语中 pickl
  • 批处理一键关闭危险端口(135 137 138 139 445)预防勒索病毒

    一键关闭危险端口 bat echo off color 1f title 关闭常见的危险端口 echo 正在开启Windows防火墙 echo netsh advfirewall set currentprofile state on gt
  • 备份BOM T-SQL

    转载请注明出处 联系我 t39q 163 com 本人热衷于数据库技术及算法的研究 志同道合之士 欢迎探讨 ALTER PROC dbo proc BOM VersionAutoUpgrade company NVARCHAR 20 Par
  • input type=file选择图片按钮样式修改与图片预览

    1 背景 通过上图我们可以看到input type file按钮的默认样式 非常不美观 如果要自定义该按钮的样式 要如何实现呢 2 方式1样式 input覆盖整个按钮区域 并且设置完全透明
  • 图显系统DRM ENCODER和CONNECTOR完全解析

    0 引言 DRM ENCODER 和 CONNECTOR 模块由图显外设抽象而来 从传统意义上来讲 ENCODER 包含外设控制器的功能 而 CONNECTOR 包含外设 PHY 或者显示器参数 但是这两部分又紧密关联 因此 软件 DRM
  • 大神之路-起始篇

    欢迎关注 WeiyiGeek 作者 设为 星标 每天带你 基础入门 到 进阶实践 再到 放弃学习 涉及 网络安全运维 应用开发 物联网IOT 学习路径 个人感悟 等知识 花开堪折直须折 莫待无花空折枝 文章目录 第 4 部分 计算机软件与算
  • linux socket 开源库,libsocket

    README for libsocket BUILDING libsocket If you want to install both libsocket and libsocket simply use this command mkdi