|
EasySockets v2.0.0
A simple, cross platform socket library for C++.
|
An object which represents a connection between two applications. More...
#include <WindowsSocket.hpp>
Public Member Functions | |
| WindowsSocket (IpVersion ip_version, Protocol protocol) | |
| Constructor for Socket. | |
| ~WindowsSocket () | |
| WindowsSocket (const WindowsSocket &)=delete | |
| WindowsSocket & | operator= (const WindowsSocket &)=delete |
| WindowsSocket (WindowsSocket &&other) noexcept | |
| WindowsSocket & | operator= (WindowsSocket &&other) noexcept |
| void | bind_to (const EndPoint &end_point) |
| Binds a socket to the given end point. | |
| void | connect_to (const EndPoint &end_point) |
| Connects a socket to the given end point. | |
| void | listen_for_connections (int backlog) |
| Makes the socket start listening for incoming connections. | |
| WindowsSocket | accept_connection () |
| Accepts incoming connections. | |
| int64_t | receive_data (char *buffer, int buffer_size) |
| Waits to receive data from the connected end point. | |
| int64_t | receive_data_from (char *buffer, int buffer_size, EndPoint &sender_end_point) |
| Waits to receive data from any endpoint. | |
| int64_t | send_data (const char *buffer, int buffer_size) |
| Sends data to the connected end point. | |
| int64_t | send_data_to (const char *buffer, int buffer_size, const EndPoint &end_point) |
| Sends data to the provided end point. | |
An object which represents a connection between two applications.
On creation, type of ip addresses that the socket will use and the layer 4/transport layer protocol is specified.
From this, methods like .bind_to(EndPoint end_point) and .connect_to(EndPoint end_point) to give the socket an address and port so that it can start communicating with other applications.
For connectionless protocols like UDP, data can be sent and received without binding or connecting first.
Can be moved from but not copied. Members are the same across all implementations.
Constructor for Socket.
| ip_version | The version of ip addresses that the socket will use. |
| protocol | The layer 4/transport layer protocol that the socket will use. |
| es::WindowsSocket::~WindowsSocket | ( | ) |
|
delete |
|
noexcept |
| WindowsSocket es::WindowsSocket::accept_connection | ( | ) |
Accepts incoming connections.
.listen(int backlog)must be called first.
| void es::WindowsSocket::bind_to | ( | const EndPoint & | end_point | ) |
Binds a socket to the given end point.
| end_point | The endpoint that the socket will use. "0.0.0.0" will bind to all IPv4 interfaces, "::0"will bind to all IPv6 interfaces and "::"" will bind to all interfaces. |
| void es::WindowsSocket::connect_to | ( | const EndPoint & | end_point | ) |
Connects a socket to the given end point.
| end_point | The endpoint that the socket will use. |
| void es::WindowsSocket::listen_for_connections | ( | int | backlog | ) |
Makes the socket start listening for incoming connections.
Must be bound with .bind(EndPoint end_point) before being called.
| backlog | The amount of connections that can be waiting to be accepted at a time. If the amount of connections exceeds the backlog, then new connections will be dropped. Connections can be accepted with .accept_connection. |
|
delete |
|
noexcept |
| int64_t es::WindowsSocket::receive_data | ( | char * | buffer, |
| int | buffer_size ) |
Waits to receive data from the connected end point.
Must be connected to another end point.
| buffer | The buffer which data received will be placed into. |
| buffer_size | The size of the buffer provided. |
| int64_t es::WindowsSocket::receive_data_from | ( | char * | buffer, |
| int | buffer_size, | ||
| EndPoint & | sender_end_point ) |
Waits to receive data from any endpoint.
Can only be used with connectionless protocols like UDP.
| buffer | The buffer which data received will be placed into. |
| buffer_size | The size of the buffer provided. |
| sender_end_point | An out parameter will give back the end point of the sender. |
| int64_t es::WindowsSocket::send_data | ( | const char * | buffer, |
| int | buffer_size ) |
Sends data to the connected end point.
Must be connected to another end point.
| buffer | The buffer which data received will be placed into. |
| buffer_size | The size of the buffer provided. |
| int64_t es::WindowsSocket::send_data_to | ( | const char * | buffer, |
| int | buffer_size, | ||
| const EndPoint & | end_point ) |
Sends data to the provided end point.
Must be connected to another end point.
| buffer | The buffer which data received will be placed into. |
| buffer_size | The size of the buffer provided. |
| end_point | The endpoint that the data will be sent to. |