There are two kinds of TCP sockets : the "regular" ones, that send and receive data, and the listeners, that listen for incoming connections. That's why the example above has two separate pieces of code, according to the type of the socket.
With UDP there are no connections and listeners, so you don't need this stuff, things are much simpler. Forget about listeners.