All Projects → elhayra → tcp_server_client

elhayra / tcp_server_client

Licence: MIT license
A thin and simple C++ TCP client server

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to tcp server client

EasyFileTransfer
An easy way to transfer file with any size on network with tcp protocol.
Stars: ✭ 30 (-75.81%)
Mutual labels:  tcp, tcp-server, tcp-client, tcp-socket
Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (-45.97%)
Mutual labels:  tcp, tcp-server, tcp-client, tcp-socket
QTcpSocket
A simple Qt client-server TCP architecture to transfer data between peers
Stars: ✭ 62 (-50%)
Mutual labels:  tcp, tcp-server, tcp-client, tcp-socket
Oksocket
An blocking socket client for Android applications.
Stars: ✭ 2,359 (+1802.42%)
Mutual labels:  tcp, tcp-server, tcp-client, tcp-socket
Tinytcpserver
A small tcp server working under Mono or .NET (4.0) and provides hooks for handling data exchange with clients (works under mono and .net). Behaviour/protocol/reaction could be specified via custom C# script.
Stars: ✭ 14 (-88.71%)
Mutual labels:  tcp, tcp-server, tcp-client, tcp-ip
Packetsender
Network utility for sending / receiving TCP, UDP, SSL
Stars: ✭ 1,349 (+987.9%)
Mutual labels:  tcp, tcp-server, tcp-client
ctsTraffic
ctsTraffic is a highly scalable client/server networking tool giving detailed performance and reliability analytics
Stars: ✭ 125 (+0.81%)
Mutual labels:  tcp, tcp-server, tcp-client
Simpletcp
Simple wrapper for TCP client and server in C# with SSL support
Stars: ✭ 99 (-20.16%)
Mutual labels:  tcp, tcp-server, tcp-client
Hprose Nodejs
Hprose is a cross-language RPC. This project is Hprose 2.0 for Node.js
Stars: ✭ 297 (+139.52%)
Mutual labels:  tcp, tcp-server, tcp-client
React Native Tcp Socket
React Native TCP socket API for Android, iOS & macOS with client SSL/TLS support
Stars: ✭ 112 (-9.68%)
Mutual labels:  tcp, tcp-server, tcp-client
Simpletcp
A minimal non-blocking TCP server written for Python 3.
Stars: ✭ 162 (+30.65%)
Mutual labels:  tcp, tcp-server, tcp-client
Easytcp
Simple framework for TCP clients and servers. Focused on performance and usability.
Stars: ✭ 60 (-51.61%)
Mutual labels:  tcp, tcp-server, tcp-client
network
exomia/network is a wrapper library around System.Socket for easy and fast TCP/UDP client & server communication.
Stars: ✭ 18 (-85.48%)
Mutual labels:  tcp, tcp-server, tcp-client
Bizsocket
异步socket,对一些业务场景做了支持
Stars: ✭ 469 (+278.23%)
Mutual labels:  tcp, tcp-server, tcp-client
Simpleunitytcp
🖧 Simple Unity Project to show how TCP communication are builded in C# without multi-threading or Unity network (Unet) involved.
Stars: ✭ 22 (-82.26%)
Mutual labels:  tcp, tcp-server, tcp-client
tcp-net
Build tcp applications in a stable and elegant way
Stars: ✭ 42 (-66.13%)
Mutual labels:  tcp, tcp-server, tcp-client
SuperSimpleTcp
Simple wrapper for TCP client and server in C# with SSL support
Stars: ✭ 263 (+112.1%)
Mutual labels:  tcp, tcp-server, tcp-client
AsyncTcpClient
An asynchronous variant of TcpClient and TcpListener for .NET Standard.
Stars: ✭ 125 (+0.81%)
Mutual labels:  tcp, tcp-server, tcp-client
Tacopie
C++ TCP Library - NO LONGER MAINTAINED
Stars: ✭ 359 (+189.52%)
Mutual labels:  tcp, tcp-server, tcp-client
chat-app
Multithreading TCP server and client communicating over TCP/IP - Windows Forms Application.
Stars: ✭ 39 (-68.55%)
Mutual labels:  multithreading, tcp-server, tcp-client

cmake workflow

TCP server client

A thin and simple C++ TCP client and server library with examples.

Platforms Support

Currently, both linux and mac are supported

Examples

Simple tcp server-client examples. They are optimized for simplicity and ease of use/read but not for performance. However, I believe tuning this code to suite your needs should be easy in most cases. You can find code examples of both server and client under the 'examples' directory. Both the library and the examples are well documented.

Server

The server is thread-safe, and can handle multiple clients at the same time, and remove dead clients resources automatically.

Quick start

build the examples and static library file:

$ cd tcp_server_client
$ ./build

run the server and client examples: Navigate into the build folder and run in the terminal:

$ cd build

In terminal #1:

$ ./tcp_server

In terminal #2:

$ ./tcp_client

Building

This project is set to use CMake to build both the client example and the server example. In addition, CMake builds a static library file to hold the common code to both server and client.

In order to build the project you can either use the build.sh script:

$ cd tcp_server_client
$ ./build

or build it manually:

$ cd tcp_server_client
$ mkdir build
$ cmake ..
$ make

The build process generate three files: libtcp_client_server.a, tcp_client and tcp_server. The last two are the executables of the examples which can be executed in the terminal.

Building Only Server or Client

By default, the CMake configuration builds both server and client. However, you can use flags to build only one of the apps as follows:

Disabling the server build

To build only the client, disable the server build by replace the cmake .. call by:

cmake -DSERVER_EXAMPLE=OFF ..

And then run the make command as usual.

Disabling the client build

To build only the server, disable the client build by replace the cmake .. call by:

cmake -DCLIENT_EXAMPLE=OFF ..

And then run the make command as usual.

Run the Examples

Navigate into the build folder and run in the terminal:

$ ./tcp_server

You should see a menu output on the screen, we'll get back to that. In a different terminal, run the client:

$ ./tcp_client

You should see a similar menu for the client too. In addition, as mentioned, the client will try to connect to the server right away, so you should also see an output messages on both client and server terminals indicating that the connection succeeded. Now, feel free to play with each of the client/server menus. You can exchange messages b/w client and server, print active clients etc. You can also spawn more clients in other terminals to see how the server handles multiple clients.

Server-Client API

After playing with the examples, go into the examples source code and have a look at the main() function to learn how the server and client interacts. The examples are heavily documented. In addition, you can also look at the public functions in tcp_client.h and tcp_server.h to learn what APIs are available.

Server and Client Events

Both server and client are using the observer design pattern to register and handle events. When registering to an event with a callback, you should make sure that:

  • The callback is fast (not doing any heavy lifting tasks) because those callbacks are called from the context of the server or client.
  • No server / client function calls are made in those callbacks to avoid possible deadlock.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].