An implementation of socket and websocket protocol for mobile and web in one purpose in C++.
To deploy this project clone it and run.
$ git clone https://github.com/farhadiis/socket-connect
$ cd socket-connect
$ docker build -t socket-connect .
$ docker run -p 5600:5600 socket-connect
Now you can connect to this service through the socket in TCP. This connection also supports websocket frames and can be used in the web browsers.
int main(int argc, const char *argv[]) {
Socket socket;
socket.onConnect((int fd, const char *ip) {
LOG_INFO("onConnect %s, fd: %d", ip, fd);
});
socket.onDisconnect((int fd) {
LOG_INFO("onSocketDisconnect fd: %d", fd);
});
socket.onSocketInput((int fd, unsigned char *buffer, ssize_t buffer_size) {
LOG_INFO("onSocketInput fd: %d", fd);
string msg((char *) buffer, buffer_size);
LOG_INFO("data on input: %s", msg.data());
});
LOG_INFO("Start listen at 5600");
socket.startup();
return 0;
}
We're open for pull requests.