build/api-examples/Socket.cpp¶
Complete program from the Socket API reference. Save it at the path shown above and use the build command in the reference page.
Source files · Download Socket.cpp
#include "gaspardos.hpp"
#include <cstdio>
#include <cstring>
int main()
{
gaspardos::Socket socket;
if (socket.open(GO64_DGRAM) < 0)
return 1;
GO64_SocketAddress address = gaspardos::ipv4(127, 0, 0, 1, 19002);
const char message[] = "hello";
int64_t sent = socket.sendTo(message, sizeof(message) - 1, &address);
int64_t closed = socket.close();
return sent == static_cast<int64_t>(sizeof(message) - 1) && closed == 0 ? 0 : 1;
}