Version 2.0.0
Simple to use, cross-platform socket library for C++.
Features
- Supports Windows, macOS and Linux.
- TCP and UDP sockets.
- IPv4 to IPv6 conversions.
- CMake based.
Adding to your project
Cloning
git clone "https://github.com/Alex-Petrucci/EasySockets.git"
CMake
add_subdirectory(EasySockets) # change if EasySockets dir is not in root
target_link_libraries(${PROJECT_NAME} EasySockets)
Example
Below is an example of a server which waits until it receives one connection, then it waits for data from that connection, and outputs that data.
#include <EasySockets/EasySockets.hpp>
#include <iostream>
int main()
{
es::Socket server{es::IpVersion::dual_stack, es::Protocol::tcp};
char buffer[1024];
std::cout << "Received:\n" << std::string{buffer, static_cast<size_t>(bytes)} << '\n';
return 0;
}
int64_t receive_data(char *buffer, int buffer_size)
Waits to receive data from the connected end point.
Definition WindowsSocket.cpp:148
void listen_for_connections(int backlog)
Makes the socket start listening for incoming connections.
Definition WindowsSocket.cpp:126
WindowsSocket accept_connection()
Accepts incoming connections.
Definition WindowsSocket.cpp:134
void bind_to(const EndPoint &end_point)
Binds a socket to the given end point.
Definition WindowsSocket.cpp:84
Documentation
All documentation is on the EasySockets website
If something is confusing, or for some reason is not part of the documentation, feel free to post something in the discussions tab.
Changelog
You can view the changelog here.
Contributing
See CONTRIBUTING.md
If you would like to see a new feature, make a change to the library or notify us of bugs, feel free to make an issue.