0

Unix Datagram Sockets: family = AF_UNIX/AF_LOCAL type = SOCK_DGRAM

If I want to start a server for this type of socket, do I need to mark it as listening by calling 'listen' ? I was under the impression that listen only works for connection-oriented sockets.

2

No, listen() won't work on a datagram socket since there is no connection to set up or tear down. After you bind() the socket you can immediately begin sending packets by using sendto() to specify the recipient address. You can use recv() or even read() to receive packets, but you should use recvfrom() if you also want to know who sent the packet (e.g. so you can reply to them).

If you want to talk to a specific host, you can (but don't need to) use connect() on a datagram socket. In this case, connect() won't actually establish a connection with the remote host; it will just set the socket's default destination, so you can use functions like send() or write() that don't let you specify a destination.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.