View on GitHub

DSFML

dsfml.network.tcplistener

A module containing the TcpListener class.

class TcpListener: dsfml.network.socket.Socket;
Socket that listens to new TCP connections.

A listener socket is a special type of socket that listens to a given port and waits for connections on that port.

This is all it can do.

When a new connection is received, you must call accept and the listener returns a new instance of sf::TcpSocket that is properly initialized and can be used to communicate with the new client.

Listener sockets are specific to the TCP protocol, UDP sockets are connectionless and can therefore communicate directly. As a consequence, a listener socket will always return the new connections as sf::TcpSocket instances.

A listener is automatically closed on destruction, like all other types of socket. However if you want to stop listening before the socket is destroyed, you can call its close() function.

this();
Default constructor

ushort getLocalPort();
Get the port to which the socket is bound locally.

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





Returns:
Port to which the socket is bound.

void setBlocking(bool blocking);
Tell whether the socket is in blocking or non-blocking mode.

In blocking mode, calls will not return until they have completed their task. For example, a call to Receive in blocking mode won't return until some data 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.





Params:
bool blocking True to set the socket as blocking, false for non-blocking.

Status accept(TcpSocket socket);
Accept a new connection.

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





Params:
TcpSocket socket Socket that will hold the new connection.

Returns:
Status code.

Status listen(ushort port);
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.





Params:
ushort port Port to listen for new connections.

Returns:
Status code.

bool isBlocking();
Set the blocking state of the socket.

In blocking mode, calls will not return until they have completed their task. For example, a call to Receive in blocking mode won't return until some data 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.





Returns:
True if the socket is blocking, false otherwise.