1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#include <base/io.h>
4#include <base/net.h>
5#include <base/os.h>
6
7enum
8{
9 NUM_SOCKETS = 64
10};
11
12static void Run(NETADDR Dest)
13{
14 NETSOCKET aSockets[NUM_SOCKETS];
15
16 for(auto &Socket : aSockets)
17 {
18 NETADDR BindAddr = {.type: NETTYPE_IPV4, .ip: {0}, .port: 0};
19 Socket = net_udp_create(bindaddr: BindAddr);
20 }
21
22 while(true)
23 {
24 unsigned char aData[1024];
25 int Size = 0;
26 int SocketToUse = 0;
27 io_read(io: io_stdin(), buffer: &Size, size: 2);
28 io_read(io: io_stdin(), buffer: &SocketToUse, size: 1);
29 Size %= 256;
30 SocketToUse %= NUM_SOCKETS;
31 io_read(io: io_stdin(), buffer: aData, size: Size);
32 net_udp_send(sock: aSockets[SocketToUse], addr: &Dest, data: aData, size: Size);
33 }
34}
35
36int main(int argc, const char **argv)
37{
38 CCmdlineFix CmdlineFix(&argc, &argv);
39 NETADDR Dest = {.type: NETTYPE_IPV4, .ip: {127, 0, 0, 1}, .port: 8303};
40 Run(Dest);
41 return 0;
42}
43