nudsfml.network.tcplistener

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 $(TCPSOCKET_LINK) 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 $(TCPSOCKET_LINK) 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.

Members

Classes

TcpListener
class TcpListener

Socket that listens to new TCP connections.

Functions

sfTcpListener_accept
Socket.Status sfTcpListener_accept(sfTcpListener* listener, sfTcpSocket* connected)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
sfTcpListener_create
sfTcpListener* sfTcpListener_create()
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
sfTcpListener_destroy
void sfTcpListener_destroy(sfTcpListener* listener)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
sfTcpListener_getLocalPort
ushort sfTcpListener_getLocalPort(const(sfTcpListener)* listener)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
sfTcpListener_isBlocking
bool sfTcpListener_isBlocking(sfTcpListener* listener)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
sfTcpListener_listen
Socket.Status sfTcpListener_listen(sfTcpListener* listener, ushort port, IpAddress* address)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
sfTcpListener_setBlocking
void sfTcpListener_setBlocking(sfTcpListener* listener, bool blocking)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Structs

sfTcpListener
struct sfTcpListener
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Examples

// Create a listener socket and make it wait for new
// connections on port 55001
auto listener = new TcpListener();
listener.listen(55001);

// Endless loop that waits for new connections
while (running)
{
    auto client = new TcpSocket();
    if (listener.accept(client) == Socket.Status.Done)
    {
        // A new client just connected!
        writeln("New connection received from ", client.getRemoteAddress());
        doSomethingWith(client);
    }
}

See Also

$(TCPSOCKET_LINK), $(SOCKET_LINK)

Meta