0

I'm trying to make a very basic Server that uses sockets to connect two different processes. When attempting to connect to the server from the client nothing happens until I end the the process, then the amount of clients I have connected to the server is the amount of times it loops through. Why does it wait until after I kill the process to display the information?

Server side:

while(1){
    if (listen(s1, 1) == -1) {
        printf("/nListen error");
        exit(1);
    }
    s0 = accept(s1, NULL, NULL);
    if (s0 == -1) {
        printf("/nAccept Error");
        exit(1);
    }
    else
        printf("/n Successfully Connected to client");
    printf("attempting to write");
    write(s0, "this", 3);
    close(s0);
}

Client side:

int main(int args, char* argv[]) {
unlink("Client");
int s0, s1;
struct sockaddr name0 = { AF_UNIX, "Client" };
s0 = socket(AF_UNIX, SOCK_STREAM, 0);
if(s0 == -1)
    return -1;
socklen_t clientlen = sizeof(struct sockaddr) + 7;
bind(s0, &name0, clientlen);

struct sockaddr name1 = { AF_UNIX, "Server" };
s1 = socket(AF_UNIX, SOCK_STREAM, 0);
if(s1==-1)
    return -1;
socklen_t serverlen = sizeof(struct sockaddr) + 7;
bind(s1, &name1, clientlen);
if (connect(s0, &name1, serverlen) == -1) {
    printf("connect() fail\n");
    return -1;
}
card** deck = malloc(sizeof(card) * 52);
char buf[20];
read(s1, buf, sizeof(buf));
printf(buf);
printf("\nBye");
return 0;
}
TemporaryFix
  • 2,008
  • 3
  • 30
  • 54

0 Answers0