Post by R.WieserHello all,
I would like to know if its possible to have Windows "accept" an UDP
connection in the same way it accepts a TCP one: the receiver creating a new
socket and return that to the caller to use for further communication.
I've already written such a mechanism (which works well enough), but am
wondering if its already build in ... (don't think so, but I do not know
everything :-) )
There isn't any such thing in the Unix-derived sockets API.
Like you, I've also developed a purely library based implementation
of the concept of accepting a UDP socket.
It's probably entirely different from what you have, but maybe not.
This is implemented in the TXR Lisp language as "Datagram Socket
Streams".
https://www.nongnu.org/txr/txr-manpage.html#N-01F91F35
The idea is that a single UDP datagram constitutes a stream. The
server calls sock-accept on the "listening" UDP socket. The operation
returns a new socket when a request datagram arrives. Read operations on
that new socket will successively retrieve bytes from that one and only
UDP datagram. The socket is associated with the address of the client,
and has a reference to the original UDP server socket, which allows
write operations on the accepted socket to send back a datagram
reply to the original client.
There is a test case in the TXR Lisp test suite which exercises
it:
http://www.kylheku.com/cgit/txr/tree/tests/014/socket-basic.tl
There is a top-level loop in this test case which iterates the
socktype variable over the values sock-dgram sock-stream.
So basically the entire test case is repeated twice: once with
datagram sockets and once with stream sockets. (In the AF_INET
address family; i.e. UDP and TCP).
Obvoiusly, "one datagram is one stream" has limitations. Clients have to
send their entire request at once; we cannot have a back and forth chat
over this "connection". It's essentially half duplex. If we have a new
request, we make a new connection. The unreliability of UDP isn't
addressed either.
But what this enables you to do is write a UDP-based communication
solution (which doesn't mind these restrictions) and then make it work
over TCP also with no code changes.