There’s no need to give up default listening addresses either.
Provide an array of them as the 4th parameter of the runSocketplateApp function.
If default listening addresses are provided, the server will use them when non are specified through args.
To close a connection, simply call .close() on it.
Forgetting to close connections is nothing to worry about, though.
Socketplate’s workers will close still-alive connctions once a connection handler exits.
Received data is retrieved via user-provided buffers.
delegate(SocketConnectionconnection)
{
// allocate a new buffer (with a size of 256 bytes)ubyte[] buffer = newubyte[](256)
// read data into the bufferautobytesReceived = connection.receive(buffer);
if (bytesReceived <= 0) {
// connection either got closed or timed out,// or an error ocurredreturn;
}
// slice the buffer (to view only the received data)ubyte[] data = buffer[0 .. bytesReceived];
// do something…
}
delegate(SocketConnectionconnection)
{
// allocate a new buffer (with a size of 256 bytes)ubyte[] buffer = newubyte[](256)
// read data into the buffer// note: `receiveSlice` throws on errorubyte[] data = connection.receiveSlice(buffer);
if (data.length == 0) {
// nothing received, connection got closed remotelyreturn;
}
// do something…
}
socketplate – “app entry point” helper module
Also provides all necessary public imports to quickstart coding.
Developer manual
Hello and welcome to socketplate.
How to get started
socketplate.app provides to entry points:
Both come with batteries included:
All that’s left to do is to pick either of the entry points and call the corresponding runSocketplateApp overload from your main() function.
Single connection handler
In this mode listening addresses are read from args that will usually point to the program’s command line args.
This way, an end-user can specify listening addresses by passing -S <socket> parameters.
Sample code:
There’s no need to give up default listening addresses either. Provide an array of them as the 4th parameter of the runSocketplateApp function. If default listening addresses are provided, the server will use them when non are specified through args.
Manual handler setup
This variation allows you to setup listeners through code instead.
Code sample:
In practice you might want to use callback variables and reuse them across listeners:
Connection usage
Established connections are made available as socketplate.connection.SocketConnection.
To close a connection, simply call .close() on it.
Sending
Sending data is super easy:
Receiving
Received data is retrieved via user-provided buffers.
Logging
See socketplate.log for details.