The easiest way of creating TCP sockets and implementing message transfers. Through this library you can create your own servers and clients. Bear in mind that this project is not product-safe. It is only for experimenting socket programming, and having a good understanding of the underlying structure of the networks.
- Download the repo.
- Copy the src folder to your workspace
- Add
#include "src/connection.h"
to the file you want to use the sockets. - Use the methods described below
One of the aims of this project is to make it a library, however, it is not at that stage yet.
connect_socket(char *hostname, int port):
Returns a socket file descriptor that is connected to the hostname on the given port.
accept_connection(int sockfd):
Accepts a connection on the specified socket.
listen_socket(int port):
Returns a socket file descriptor that is listening on the specified port.
recv_msg(int sockfd, std::string* message):
Receives a message from the socket, assigns it to the message parameter for further processing.
You are more than welcomed to contribute to this project. You can select one of the issues from the TODO list. Or you can come up with your own idea.
- Turn the package into a library
- Send message over the tcp socket
- Receive message over the tcp socket
- Protobuf support
- Async IO - nonblocking accept connection and message transfer
- Concurrency support
- Receive message until the read_byte is less than or equal to 0.