Wrapper for linux TCP/UDP/unix/USB socket connections

Overview

Socket Connection wrapper shared library

Shared library that realize sockets connections and could transfer data-packages.

Navigation

Installation:


Compile from source

  • git clone https://github.com/DGolgovsky/sock_connect.git clone git repository
  • cd sock_connect change directory to cloned repo-dir
  • ./ci-build.sh -r compile latest release version
  • also you can use ./ci-build.sh -h for print help information for another variations of building
  • cd build jump to directory with compiled objects
  • sudo make install install library as root

Package provides headers installs at /usr/include and .so library, puts to /usr/lib

Usage:


  • Include header in your source files where do you need it.
#include <sock_connect.h>
  • Compile with -lsock_connect

Variations:


  1. Connection with TCP transmission
    • auto tcp = std::make_shared<Connector<TCP>>(IP, PORT);
  2. Connection with UDP transmission
    • auto udp = std::make_shared<Connector<UDP>>(INADDR_ANY, PORT);
  3. Connection with UNIX-domain sockets transmission
    • auto unix = std::make_shared<Connector<UNIX>>(sun_path);
  4. Connection with USB transmission
    • auto usb = std::make_shared<Connector<USB>>(dev_path, speed);
  5. DEPRECATED Transform const char* ip-addr 192.168.1.42 to uint32_t
    • uint32_t IP = ip_to_int(argv[1]);

Examples:


  • Receiving TCP as client:
uint16_t msg = 0;
auto recv_sz = sizeof(uint16_t);

/* Create new socket connection */
auto tcp = std::make_shared<Connector<TCP>>(IP, PORT);
while (tcp->Status()) {
    // While tcp establish connection to server
    if (tcp->Connect()) {
        // While data receiving do something with it
        // if tcp connection lost tcp->Receive returns false
        while (tcp->Receive(&msg, recv_sz)) {
            // do_something with received data
            // ...
        }
        // Trying reconnect if connection lost
        tcp.reset(new Connector<TCP>(IP, PORT));
    }
}
  • Receiving TCP as multi-server:
template<class T>
void handler(T tcp, int client_id) {
    tcp->assign_thread(client_id);
    uint16_t msg = 0;
    auto recv_sz = sizeof(uint16_t);
    while ((tcp->Receive(&msg, recv_sz))) {
        // do_something with received message
        // ...
    }
    tcp->Shutdown(client_id);
}

/* Used if [this] - recv server */
void receiver()
{
    /* Creating new connection */
    auto tcp = std::make_shared<Connector<TCP>>(IP, PORT);

    tcp->Bind(false); /* You can use it as TCP->Bind(); for bind && listen */
    tcp->Listen(); /* You may don't need this part if you bind with (true) option */

    int client_id = 0;
    while ((client_id = tcp->Accept()) > 0) {
        /* Accepting new connections and start receiving with the new thread */
        std::thread thread(handler<decltype(tcp)>, tcp, client_id);
        thread.detach();
    }
}
  • Sending TCP as client to server, broadcasting UDP:
auto tcp = std::make_shared<Connector<TCP>>(INADDR_LOOPBACK, PORT); // 127.0.0.1
auto udp = std::make_shared<Connector<UDP>>(INADDR_ANY, PORT); // 0.0.0.0

uint16_t msg = 0;
auto msg_sz = sizeof(uint16_t);

// Infinite loop. This allow execute tcp_sender as daemon
while (true) {
    if (tcp->Connect()) {
        // If connection successful,
        // send data while Status() returns true
        while (tcp->Status()) {
            msg = rand() % 50; // Generate random data
            if (msg) {
                // Trying to send message
                // Continue if sending is failure,
                // Also tcp->Status() will return false
                if (!tcp->Send(&msg, msg_sz)) continue;
                // Send udp package
                udp->Send(&msg, msg_sz);                
            }
        }
        // Reconnecting if connection lost
        tcp.reset(new Connector<TCP>(INADDR_LOOPBACK, PORT));
    }
}

License:


Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Owner
Dmitry Golgovsky
C++ developer
Dmitry Golgovsky
Portable, single-file, protocol-agnostic TCP and UDP socket wrapper, primarily for game networking

Documentation This is a header-only library, as such most of its functional documentation is contained within the "header section" of the source code

null 62 Mar 23, 2022
Provide translation, currency conversion, and voting services. First using telnet you create a connection to a TCP socket, then the server connects to 3 UDP sockets hosted on other servers to do tasks.

to run micro servers g++ translator.cpp -o translator ./translator <port 1> g++ voting.cpp -o voting ./voting <port 2> g++ currency_converter.cpp -o c

Jacob Artuso 1 Oct 29, 2021
Asynchronous, Header-only C++ HTTP-over-(TCP|UNIX Socket|STDIO) Library

CXXHTTP A C++ library implementing an asynchronous HTTP server and client. To clone this library, make sure you also clone the submodules. The --recur

null 25 Mar 19, 2021
A socket daemon to multiplex connections from and to iOS devices

usbmuxd A socket daemon to multiplex connections from and to iOS devices. Features usbmuxd stands for "USB multiplexing daemon". This daemon is in cha

libimobiledevice 1.1k Jun 28, 2022
A protocol for secure client/server connections over UDP

netcode netcode is a simple connection based client/server protocol built on top of UDP. It has the following features: Encrypted and signed packets S

The Network Protocol Company 2.2k Jun 26, 2022
A protocol for secure client/server connections over UDP

netcode netcode is a simple connection based client/server protocol built on top of UDP. It has the following features: Encrypted and signed packets S

The Network Protocol Company 2.2k Jun 26, 2022
null 4 Feb 25, 2022
Windows named pipe server that forwards connections to given TCP server

PipeTcp An asynchronous Windows named pipe server that forwards connections to given TCP server. Pre-built binaries can be found in Releases. Invocati

Jinoh Kang 4 May 23, 2022
Small utility that leverages eBPF to dump the traffic of a unix domain socket

UnixDump UnixDump is a small eBPF powered utility that can be used to dump unix socket traffic. System requirements This project was developed on a Ub

Guillaume Fournier 5 Dec 1, 2021
Faster termux-am implementation that connects to a receiver in termux-app using a unix socket

termux-am-socket This is a small program for sending commands to the Termux:API app, thereby allowing terminal programs to use the Android API. The pr

Termux 18 Apr 30, 2022
A modern C++ network library for developing high performance network services in TCP/UDP/HTTP protocols.

evpp Introduction 中文说明 evpp is a modern C++ network library for developing high performance network services using TCP/UDP/HTTP protocols. evpp provid

Qihoo 360 3k Jun 27, 2022
Mongoose Embedded Web Server Library - a multi-protocol embedded networking library with TCP/UDP, HTTP, WebSocket, MQTT built-in protocols, async DNS resolver, and non-blocking API.

Mongoose - Embedded Web Server / Embedded Networking Library Mongoose is a networking library for C/C++. It implements event-driven non-blocking APIs

Cesanta Software 8.5k Jun 29, 2022
Built a client-server application using TCP and UDP sockets, in which the clients can subscribe/unsubscribe to various topics.

Built a client-server application using TCP and UDP sockets, in which the clients can subscribe/unsubscribe to various topics.

null 1 Jun 22, 2022
Winpcap-based network packet capture tool, support TLS (part), UDP, ICMP, TCP, ARP, DNS and other protocol analysis, interface reference wireshark.

Winpcap-based network packet capture tool, support TLS (part), UDP, ICMP, TCP, ARP, DNS and other protocol analysis, interface reference wireshark.

null 35 Jun 25, 2022
A TCP / UDP program supporting multiple test scenarios

sock_test A TCP / UDP program supporting multiple test scenarios The current communication protocol only supports UDP. TCP will be supported later. Ho

null 4 Mar 8, 2022
📡 TCP/UDP port redirector

rinetd, by Thomas Boutell and Sam Hocevar. Released under the terms of the GNU General Public License, version 2 or later. This program is used to eff

Sam Hocevar 420 Jun 28, 2022
A Tcp/Ip stack implementation on top of Solarflare ef_vi, and a C++ headers only framework for tcp multiplexing client/server.

Efvitcp Efvitcp is a tcp library using Solarflare ef_vi interface on linux, and also a tcp multiplexing framework for both C++ client and server progr

Meng Rao 17 Jun 9, 2022
an easy implementation of a multi-process tcp server and a multi-thread tcp client

一个TCP多进程服务器-多线程客户端的简单实现。 客户端类似Apache ab的测试功能,能够通过向某一个ip端口发送指定并发量和总数量的tcp短连接;服务端处理tcp短连接,每来一条消息就打印一条log。 使用cmake编译,建议在vscode里编译,或者命令行 # 终端进入目录 mkdir bu

adin 1 Nov 28, 2021
A single-header socket library for both Linux and Windows

COMS What is COMS? COMS is a single-header library designed to be simple to use. It supports TCP and UDP, Server and Client. Available for Windows and

null 5 Dec 23, 2021