Home

Awesome

cpp-Socket

Current build status : Build Status

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 :

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.


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.


namespace ntw
{
    void dispatch(int id,SocketSerialized& request)
    {
        switch(id)
        {
            case ntw::FuncWrapper::srv::FUNCTONS_ID::UNKNOW :
            {
                std::cerr<<"[ERROR] dispatch, FUNCTONS_ID UNKNOW"<<std::endl;
            }break;
            case 1 :
            {
                exec(getVersion,request);
            }break;
            case  2 :
            {
                exec(testParamInt,request);
            }break;
            default:
                std::cerr<<"[ERROR] FuncWrapper::dispatch, FUNCTONS_ID not find: "<<id<<std::endl;
        }
    }
}

You can build the lib with cmake.