CSFML - C binding of the Simple and Fast Multimedia Library

CSFML 3.0.0
Loading...
Searching...
No Matches
Functions
TcpListener.h File Reference
`#include <CSFML/Network/Export.h>`
`#include <CSFML/Network/IpAddress.h>`
`#include <CSFML/Network/SocketStatus.h>`
`#include <CSFML/Network/Types.h>`

Go to the source code of this file.

## Functions
sfTcpListener * | sfTcpListener_create (void)
| Create a new TCP listener.
void | sfTcpListener_destroy (const sfTcpListener *listener)
| Destroy a TCP listener.
void | sfTcpListener_setBlocking (sfTcpListener *listener, bool blocking)
| Set the blocking state of a TCP listener.
bool | sfTcpListener_isBlocking (const sfTcpListener *listener)
| Tell whether a TCP listener is in blocking or non-blocking mode.
unsigned short | sfTcpListener_getLocalPort (const sfTcpListener *listener)
| Get the port to which a TCP listener is bound locally.
sfSocketStatus | sfTcpListener_listen (sfTcpListener *listener, unsigned short port, sfIpAddress address)
| Start listening for connections.
void | sfTcpListener_close (sfTcpListener *listener)
| Stop listening and close the socket.
sfSocketStatus | sfTcpListener_accept (sfTcpListener *listener, sfTcpSocket **connected)
| Accept a new connection.
unsigned short | sfTcpListener_anyPort (void)
| Return the special value that tells the system to pick any available port.

## Function Documentation

## ◆ sfTcpListener_accept()

sfSocketStatus sfTcpListener_accept | ( | sfTcpListener * | listener,
|  | sfTcpSocket ** | connected )

Accept a new connection.

If the socket is in blocking mode, this function will not return until a connection is actually received.

The connected argument points to a valid sfTcpSocket pointer in case of success (the function returns sfSocketDone), it points to a NULL pointer otherwise.

Parameters

  listener | TCP listener object
  connected | Socket that will hold the new connection

Returns
  Status code

## ◆ sfTcpListener_anyPort()

unsigned short sfTcpListener_anyPort | ( | void |  | ) |

Return the special value that tells the system to pick any available port.

Returns
  The value to use for any port

## ◆ sfTcpListener_close()

void sfTcpListener_close | ( | sfTcpListener * | listener | ) |

Stop listening and close the socket.

This function gracefully stops the listener. If the socket is not listening, this function has no effect.

Parameters

  listener | TCP listener object

## ◆ sfTcpListener_create()

sfTcpListener * sfTcpListener_create | ( | void |  | ) |

Create a new TCP listener.

Returns
  A new sfTcpListener object

## ◆ sfTcpListener_destroy()

void sfTcpListener_destroy | ( | const sfTcpListener * | listener | ) |

Destroy a TCP listener.

Parameters

  listener | TCP listener to destroy

## ◆ sfTcpListener_getLocalPort()

unsigned short sfTcpListener_getLocalPort | ( | const sfTcpListener * | listener | ) |

Get the port to which a TCP listener is bound locally.

If the socket is not listening to a port, this function returns 0.

Parameters

  listener | TCP listener object

Returns
  Port to which the TCP listener is bound

## ◆ sfTcpListener_isBlocking()

bool sfTcpListener_isBlocking | ( | const sfTcpListener * | listener | ) |

Tell whether a TCP listener is in blocking or non-blocking mode.

Parameters

  listener | TCP listener object

Returns
  true if the socket is blocking, false otherwise

## ◆ sfTcpListener_listen()

sfSocketStatus sfTcpListener_listen | ( | sfTcpListener * | listener,
|  | unsigned short | port,
|  | sfIpAddress | address )

Start listening for connections.

This functions makes the socket listen to the specified port, waiting for new connections. If the socket was previously listening to another port, it will be stopped first and bound to the new port.

When providing sfTcpListener_anyPort() as port, the listener will request an available port from the system. The chosen port can be retrieved by calling sfTcpListener_getLocalPort().

If there is no specific address to listen to, pass sfIpAddress_Any

Parameters

  listener | TCP listener object
  port | Port to listen for new connections
  address | Address of the interface to listen on

Returns
  Status code

## ◆ sfTcpListener_setBlocking()

void sfTcpListener_setBlocking | ( | sfTcpListener * | listener,
|  | bool | blocking )

Set the blocking state of a TCP listener.

In blocking mode, calls will not return until they have completed their task. For example, a call to sfTcpListener_accept in blocking mode won't return until a new connection was actually received. In non-blocking mode, calls will always return immediately, using the return code to signal whether there was data available or not. By default, all sockets are blocking.

Parameters

  listener | TCP listener object
  blocking | true to set the socket as blocking, false for non-blocking