Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting "Address already in use" error using Unix socket
    primarykey
    data
    text
    <p>Writing the C source below using Unix local sockets I got an error about the address already in use. After having checked <code>man 7 Unix</code> for further informations I tried to create a sub-folder where executing my program (obviously modifying the <code>sun_path</code> field on the current folder) but the error was ever the same.</p> <p>Is there someone able to help me?</p> <p>Source code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;sys/socket.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/un.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt; #define MAXLEN 128 int main (int argc, char *argv[]){ struct sockaddr_un server; int serverfd, clientfd; socklen_t addrsize = sizeof(struct sockaddr_un); char buff[MAXLEN], *path; if (argc &lt; 2){ printf("Error: %s [MESSAGE]\n", argv[0]); return 1; } if ((serverfd = socket(AF_UNIX, SOCK_STREAM, 0)) &lt; 0){ printf("Error \"%s\" in socket()\n", strerror(errno)); exit(1); } puts("socket()"); server.sun_family = AF_UNIX; path = strcpy(server.sun_path, "/home/myhome/Dropbox/Sources/C/sub"); printf("[DEBUG]Address bound at %s\n", path); if ((bind(serverfd, (struct sockaddr*)&amp;server, addrsize)) &lt; 0){ printf("Error \"%s\" in bind()\n", strerror(errno)); exit(1); } puts("bind()"); if ((listen(serverfd, 1)) &lt; 0){ printf("Error \"%s\" in listen()\n", strerror(errno)); exit(1); } if ((clientfd = accept(serverfd, NULL, &amp;addrsize)) &lt; 0){ printf("Error \"%s\" in accept()\n", strerror(errno)); exit(1); } write(clientfd, argv[1], strlen(argv[1])); read(clientfd, buff, sizeof(buff)); puts(buff); close(clientfd); close(serverfd); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload