title: UNIX socket error : socket operation on non-socket
body: <p>I am trying to make a client-server communication using UNIX sockets and using the STREAM protocol.</p>
  
  <p>My server is running fine, but my client is not working. Whenever I try to send or receive data, I get an error : "socket operation on non-socket". I really don't see where it comes from, because my server is very similar and I don't have any problem. My server is on my local machine (127.0.0.1) and port 5000. It is open and listening (I checked with the netstat command).</p>
  
  <p>The code is there :</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;errno.h&gt;
  
  #define CHECK(ret, mes) if ((ret) == -1) {perror(mes); exit(-1);}
  
  #define STRING_LENGTH 250
  
  int createSocketINETClient(short mode, char *addr, short port)
  {
      int s;
      struct sockaddr_in moi, server;
      int moi_len, server_len;
  
      moi.sin_family = AF_INET;
      moi.sin_port = htons(port);
      moi.sin_addr.s_addr = inet_addr(addr);
  
      memset(moi.sin_zero, 0, 8);
  
      s = socket(AF_INET, mode, 0);
  
      CHECK(s, "socket");
  
      moi_len = sizeof(moi);
  
      CHECK(bind(s, (struct sockaddr*) &amp;moi, moi_len), "bind");
  
      return s;
  }
  
  void infoSocket (int s)
  {
      struct sockaddr_in sock_addr;
      socklen_t len = sizeof(sock_addr);
  
      getsockname(s, (struct sockaddr*) &amp;sock_addr, &amp;len);
  
      printf("Onfo of socket %d\n", s);
      printf("\t IP : %s\n", inet_ntoa(sock_addr.sin_addr));
      printf("\t port : %d\n\n", ntohs(sock_addr.sin_port));
  }
  
  int main ()
  {
      int bytes;
      int sock = createSocketINETClient(SOCK_STREAM, "0.0.0.0", 0);
      struct sockaddr_in serveurSock;
      int client = 0, clientSockLen = 0;
      char message[] = "I am a message that is supposed to WORK !!!!\n";
      char fromServer[STRING_LENGTH] = "";
      infoSocket(sock);
  
  
      serveurSock.sin_family = AF_INET;
      serveurSock.sin_port = htons(5000);
      serveurSock.sin_addr.s_addr = inet_addr("127.0.0.1");
  
      memset(serveurSock.sin_zero, 0, 8);
  
      CHECK(connect(sock, (struct sockaddr*) &amp;serveurSock, sizeof(serveurSock)), "connect");
  
      usleep(1000000);
  
      CHECK((bytes = send(client, message, sizeof(message), 0)), "send");
      printf("Message sent to server : %d bytes, \"%s\"\n", bytes, message);
  
      CHECK((bytes = recv(client, fromServer, sizeof(fromServer), 0)), "recv");
      printf("Message received from server : %d bytes, \"%s\"\n", bytes, fromServer);
  
      close(client);
      printf("Client released !\n\n");
  
      return 0;
  }
  </code></pre>
  
  <p>What did I do wrong ?</p>
  
  <p>EDIT : The error comes from this line :</p>
  
  <pre><code>CHECK((bytes = send(client, message, sizeof(message), 0)), "send");
  </code></pre>