title: Unix Domain Sockets with Python server and c client not working (socket file not found)
body: <p>I'm new to unix domain sockets (but not entirely new to the general concept of sockets) and tried to let a server written in Python communicate with a client written in C to learn more about them. I used the code examples from <a href="https://pymotw.com/2/socket/uds.html" rel="nofollow">https://pymotw.com/2/socket/uds.html</a> and <a href="http://beej.us/guide/bgipc/output/html/multipage/unixsock.html" rel="nofollow">http://beej.us/guide/bgipc/output/html/multipage/unixsock.html</a>. To my understanding they should be compatible. The only thing I changed was the socket path so that they are the same. However when I try to connect them (although they are in the same directory and the python server creates the socket file) the client isn't able to find the path of the socket file. When I use a Python Server and Client or C Socket and Client it works absolutely fine, but I need it to work with an Python Server and C Client. I'm running OS X, used Python 2.7 for the server and compiled the Client with gcc. </p>
  
  <hr>
  
  <p>Edit:
  Here is my Server code:</p>
  
  <pre><code>import socket
  import sys
  import os
  
  server_address = 'echo_socket'
  
  # Make sure the socket does not already exist
  try:
      os.unlink(server_address)
  except OSError:
      if os.path.exists(server_address):
          raise
  
  # Create a UDS socket
  sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  
  # Bind the socket to the port
  print &gt;&gt;sys.stderr, 'starting up on %s' % server_address
  sock.bind(server_address)
  
  # Listen for incoming connections
  sock.listen(1)
  
  while True:
      # Wait for a connection
      print &gt;&gt;sys.stderr, 'waiting for a connection'
      connection, client_address = sock.accept()
      try:
          print &gt;&gt;sys.stderr, 'connection from', client_address
  
          # Receive the data in small chunks and retransmit it
          while True:
              data = connection.recv(100)
              print &gt;&gt;sys.stderr, 'received "%s"' % data
              if data:
                  print &gt;&gt;sys.stderr, 'sending data back to the client'
                  connection.sendall(data)
              else:
                  print &gt;&gt;sys.stderr, 'no more data from', client_address
                  break
  
      finally:
          # Clean up the connection
          connection.close()
  </code></pre>
  
  <p>and here is my client code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/un.h&gt;
  
  #define SOCK_PATH "echo_socket"
  
  int main(void)
  {
      int s, t, len;
      struct sockaddr_un remote;
      char str[100];
  
      if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
          perror("socket");
          exit(1);
      }
  
      printf("Trying to connect...\n");
  
      remote.sun_family = AF_UNIX;
      strcpy(remote.sun_path, SOCK_PATH);
      len = strlen(remote.sun_path) + sizeof(remote.sun_family);
      if (connect(s, (struct sockaddr *)&amp;remote, len) == -1) {
          perror("connect");
          exit(1);
      }
  
      printf("Connected.\n");
  
      while(printf("&gt; "), fgets(str, 100, stdin), !feof(stdin)) {
          if (send(s, str, strlen(str), 0) == -1) {
              perror("send");
              exit(1);
          }
  
          if ((t=recv(s, str, 100, 0)) &gt; 0) {
              str[t] = '\0';
              printf("echo&gt; %s", str);
          } else {
              if (t &lt; 0) perror("recv");
              else printf("Server closed connection\n");
              exit(1);
          }
      }
  
      close(s);
  
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>Since I have no experience with UDS I'm grateful for any help.</p>
  
  <p>Thanks in advance!</p>