How to make two-directional unix domain sockets with SOCK_DGRAM?

后端 未结 3 1327
天命终不由人
天命终不由人 2021-01-13 03:44

I am trying to write a simple Unix datagram server/client, and am having some problems. What I want is a server that listens on a datagram socket and sends a reply to every

相关标签:
3条回答
  • 2021-01-13 04:17

    You should call connect before of trying send nothing to the echo server.

    Take a look at: http://beej.us/guide/bgipc/output/html/multipage/unixsock.html

    0 讨论(0)
  • 2021-01-13 04:22

    Take a look at the Michael Kerrisk's AF_UNIX SOCK_DGRAM example of the client/server program (client, server) published in his book The Linux Programming Interface, chapter 57.

    0 讨论(0)
  • 2021-01-13 04:31

    Socket need to have address to be addressed to receive packets. You can call bind() with unique socket filename based on the PID or in linux use autobound abstract address if to call before send:

    bind(s, (const struct sockaddr *)&sa, sizeof(sa_family_t));
    
    0 讨论(0)
提交回复
热议问题