title: How to make two-directional unix domain sockets with SOCK_DGRAM?
body: <p>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 message received, to the original sender. I decided to try first using <code>socat</code> to be the "server" and writing the client in C. I am running socat like this:</p>
  
  <pre><code>socat UNIX-DGRAM:/tmp/test.socket,fork EXEC:echo
  </code></pre>
  
  <p>To the best of my understanding this should listen on <code>/tmp/test.socket</code> and reply to everything that is received with the same string? Then I have a client program that looks like this (error checking removed for clarity):</p>
  
  <pre><code>int s = socket(AF_UNIX, SOCK_DGRAM, 0);
  struct sockaddr_un sa;
  sa.sun_family = AF_UNIX;
  strcpy(sa.sun_path, "/tmp/test.socket");
  
  const char *data = "Testing data";
  int err = sendto(s, data, strlen(data), 0, (struct sockaddr *)(&amp;sa), sizeof(struct sockaddr_un));
  
  printf("Sent!\n");
  
  unsigned char *buffer = malloc(BUFFER_LENGTH);
  struct sockaddr_storage recv_sa;
  int recv_sa_len = 0;
  int recv_len = recvfrom(s, buffer, BUFFER_LENGTH, 0, (struct sockaddr *)&amp;recv_sa, &amp;recv_sa_len);
  
  for (int i = 0; i &lt; recv_len; i++) {
      putc(buffer[i], stdout);
  }
  printf("\n");
  </code></pre>
  
  <p>It should send the packet (that works), receive a packet, and then print it out, but the program doesn't seem to be capable of receiving the packet. What am I doing wrong here, or do I have a fundamental misunderstanding about Unix sockets? Thanks!</p>