Hi all, i have a little problem, here there is a function:
Code:
/* the struct sockaddr_un sa is a global variable */
channel_t openConnection(const char* path) {
channel_t ch;
int count=5;
ec_null1( path, EINVAL )
if (strlen(path) > UNIX_PATH_MAX) {
errno=EINVAL;
return SOCKNAMETOOLONG;
}
if (0!=strncmp(sa.sun_path, path, UNIX_PATH_MAX))
strncpy(sa.sun_path, path, UNIX_PATH_MAX);
if (sa.sun_family!=AF_UNIX)
sa.sun_family=AF_UNIX;
ec_neg1( (ch=socket(AF_UNIX, SOCK_STREAM, 0)), 0 )
while (connect((int)ch, (struct sockaddr*)&sa, sizeof(sa))==-1) {
if (errno==ENOENT) {
if (count--==0) return -1;
sleep(1);
continue;
}
else return -1;
}
return ch;
}
That's the code a client executes in order to connect with a server.
I would like it to try to connect at most 5 times, but if i start the client without start the server this is what happen:
Code:
Error during client execution: Connection refused
"Connection refused" it's printed by perror().
I'm a beginner with sockets, thanks in advance!