MXVK Vulkan Framework
0.33.1
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
send.cpp
Go to the documentation of this file.
1
#include "
mxnetwork/socket.hpp
"
2
#include <atomic>
3
#include <cstdlib>
4
#include <iostream>
5
#include <signal.h>
6
#include <string>
7
#include <vector>
8
9
int
main
(
int
argc,
char
**argv) {
10
if
(argc != 3) {
11
std::cerr <<
"Usage: "
<< argv[0] <<
" <host> <port>\n"
;
12
return
EXIT_FAILURE;
13
}
14
try
{
15
mxnetwork::Socket
sock(
mxnetwork::SocketType::TYPE_INET_DGRAM
);
16
if
(sock.
connect
(argv[1], argv[2])) {
17
std::cout <<
"Sending. UDP datagram on port "
<< argv[1] <<
"...\n"
;
18
std::string data =
"Hello, World!\n"
;
19
sock.
sendto
(data.c_str(), data.length());
20
}
21
}
catch
(
const
mxnetwork::Exception
&e) {
22
std::cerr <<
"Exception: "
<< e.
text
() <<
"\n"
;
23
return
EXIT_FAILURE;
24
}
25
return
EXIT_SUCCESS;
26
}
mxnetwork::Exception
Lightweight exception wrapper for MXNetwork failures.
Definition
exception.hpp:11
mxnetwork::Exception::text
std::string text() const
Return the stored error text.
Definition
exception.cpp:5
mxnetwork::Socket
C++ wrapper around the MXNetwork socket API.
Definition
socket.hpp:57
mxnetwork::Socket::sendto
ssize_t sendto(const void *buf, size_t bytes)
Send a datagram using the configured socket type.
Definition
socket.cpp:207
mxnetwork::Socket::connect
bool connect(const std::string_view host, const std::string_view port)
Connect to a remote Internet endpoint.
Definition
socket.cpp:80
main
int main(int argc, char **argv)
Definition
main.cpp:173
mxnetwork::SocketType::TYPE_INET_DGRAM
@ TYPE_INET_DGRAM
IPv4 datagram socket.
Definition
socket.hpp:47
socket.hpp
MXNetwork
examples
udp-send
send.cpp
Generated by
1.18.0