Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Krozark/cpp-Socket

Some class to help to construct client/server with soket and serilized datas.
https://github.com/Krozark/cpp-Socket

cpp11 socket

Last synced: about 2 months ago
JSON representation

Some class to help to construct client/server with soket and serilized datas.

Awesome Lists containing this project

README

        

cpp-Socket
==========

Current build status :
[![Build Status](https://travis-ci.org/Krozark/cpp-Socket.png?branch=master)](https://travis-ci.org/Krozark/cpp-Socket)

Testing
=======

Ubuntu 12.04+ x86/64
Windows xp x86

Version : 0.2

Some class to help to construct client/server with soket and serilized datas.

It also make some methode to make binary RPC. The binary is translate using the serializer before the send.

the data are send like this :
|size|function id|param...|
and the responce is like that :
|size|response|

Note:
It's important to know witch type are the parameters and the order.
It's the same for the result of the call.
Some function are build to don't make mistake :

* Client::call(R (\*fun)(SocketSerialized&,Args... ),Args ...)
* Server::exec(R (\*fun)(SocketSerialized&,Args ...),Args...)

Test on Ubuntu 12+ x64, but based on multiplatforme code.
Used std::thread and std::mutex.

Important
=========

You have to define your function dispatch. See the doc for more detail.

```C++

int dispatch(int id,ntw::SocketSerialized& request) //this function have to be made for a server, unless it will crash on first request. Not use by clients.
{
//your code
return 0;
};

int main(int argc,char* argv[])
{
ntw::Socketinit(dispatch); //init for windows and the server callback
//code
//ntw::Socket::close(); //clean the context
return 0;
}

```

Class
-----

All class are in ntw namespace.

* ntw::Config
* define some values use for init server, client and SelectManager.
* max_connexion;
* port_server;
* port_client;
* default_timeout;

* ntw::Serializer
* allow you to add datas to the buffer that are convert in Big Endian for the network
* allow you to add custom operators \<\< and \>\> for easily use vour own class/stuct to convert.

* ntw::Socket
* use C socket, and put them in a class to use them more easily

* ntw::SocketSerialized
* Extand Socket and Serializer.
* Simply add that you want in this soket (using \<\< operator) send it, and get data (with \>\> operator)
* RPC call are made using this Socket class.

* ntw::SelectManager
* Manage some Soket (just add some in it) and execute callback whene critera are satisfy (read,write, except)
* Run in a different thread for performence

* ntw::BalancingSelector
* A groupe of SelectManager that do the same. It's use to split the number of socket to manage in defferent thread without having to do it.

* ntw::FuncWrapper
* This class define some (static) base functions for the communication
* This class use a dispatch function tha you have to build
* exec is a shortcut tha unpack param of the function in firs param, containing in the request, and call it.

```C++

namespace ntw
{
void dispatch(int id,SocketSerialized& request)
{
switch(id)
{
case ntw::FuncWrapper::srv::FUNCTONS_ID::UNKNOW :
{
std::cerr<<"[ERROR] dispatch, FUNCTONS_ID UNKNOW"<