[Usocket-devel] socket-listen lacks UDP support

Chun Tian (binghe) binghe.lisp at gmail.com
Mon Apr 21 22:13:06 UTC 2014


Hi Bob,

SOCKET-LISTEN (even the correspond BSD socket function, listen()) is for TCP only. To create a simple, single-threaded UDP server, you can use SOCKET-CONNECT with LOCAL-HOST and LOCAL-PORT keyword arguments, which is mentioned in USOCKET's API document [1]:

	local-host and local-port, when specified, will cause the socket calling bind() on local address. 
	This is useful for selecting interfaces to send, or listening on UDP port.
	Note: use only one of them are allowed when reasonable (listen on wildcard address, or bind to random free port).

Once you have created such a UDP socket, you can repeatedly read that socket to get a request from clients and then send out the reply packet back to the clients.  You can take a look at the implementation of USOCKET:SOCKET-SERVER and internal function UDP-EVENT-LOOP for example.   As far as I know, most kinds of real UDP servers (i.e. lightweight DNS or SNMP servers) could work in this simple way, although complex (or heavy loaded) UDP services like TFTP servers cannot work (require multi-threading, but the creation of sockets are the same way).

Hope this helps,

Chun Tian (binghe)

[1] http://common-lisp.net/project/usocket/api-docs.shtml

Il giorno 22/apr/2014, alle ore 02:41, Robert Brown <robert.brown at gmail.com> ha scritto:

> The socket-listen function in backend/sbcl.lisp does not
> support ":type :datagram :protocol :udp".  Instead, it always
> creates a stream TCP socket.  I think the fix is to use
> code similar to that in socket-connect for UDP datagram
> sockets.
> 
> Bob
> 
> _______________________________________________
> Usocket-devel mailing list
> Usocket-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel





More information about the usocket-devel mailing list