B
Berk Birand
Hi,
I've been battling to get this for a long while now, but failed miserably
after 6 hours. I'm trying to establish a client/server connection using
low-level UNIX socket system calls. I am running into some troubles that I
for some reason can't understand.
I know that posting code and asking "What's wrong?" is not good
netiquette, but as of now I have no clue as to what might be wrong. I've
been following everything by the book.
The code is supposed to get a directory listing, and send it to a client.
Here's the server-side code
struct dirent **namelist;
int n;
n = scandir("./public/", &namelist, 0, alphasort);
if (n < 0)
perror("scandir");
else {
while(n--) {
printf("%s\n", namelist[n]->d_name);
send(sock,namelist[n]->d_name, strlen(namelist[n]->d_name), 0);
free(namelist[n]);
}
free(namelist);
}
sock is the socket, and it's been opened using the standard library calls.
Here's the code for the client
while ((n = recv(sock, buf, BUFFER_LEN, 0)) > 0) {
printf("%s", buf);
//write((int) stdout, &buf, strlen(buf));
}
This for some reason doesn't work. buf is declared as
char buf[BUFFER_LEN];
The client doesn't print anything! And it doesn't get out of that loop
either.
I would really appreciate if you could point me to some possible
mistakes..
Thanks,
Berk Birand
I've been battling to get this for a long while now, but failed miserably
after 6 hours. I'm trying to establish a client/server connection using
low-level UNIX socket system calls. I am running into some troubles that I
for some reason can't understand.
I know that posting code and asking "What's wrong?" is not good
netiquette, but as of now I have no clue as to what might be wrong. I've
been following everything by the book.
The code is supposed to get a directory listing, and send it to a client.
Here's the server-side code
struct dirent **namelist;
int n;
n = scandir("./public/", &namelist, 0, alphasort);
if (n < 0)
perror("scandir");
else {
while(n--) {
printf("%s\n", namelist[n]->d_name);
send(sock,namelist[n]->d_name, strlen(namelist[n]->d_name), 0);
free(namelist[n]);
}
free(namelist);
}
sock is the socket, and it's been opened using the standard library calls.
Here's the code for the client
while ((n = recv(sock, buf, BUFFER_LEN, 0)) > 0) {
printf("%s", buf);
//write((int) stdout, &buf, strlen(buf));
}
This for some reason doesn't work. buf is declared as
char buf[BUFFER_LEN];
The client doesn't print anything! And it doesn't get out of that loop
either.
I would really appreciate if you could point me to some possible
mistakes..
Thanks,
Berk Birand