Server Socket Example in C

Here is my code..
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
 
#define BACKLOG 4
int main() {
 
    int s,c;
    unsigned int b;
    struct sockaddr_in sa;
    time_t t;
    struct tm *tm;
    FILE *client;
 
    s = socket(PF_INET, SOCK_STREAM, 0);
    bzero(&sa, sizeof sa);
 
    sa.sin_family = AF_INET;
    sa.sin_port = htons(5001);
 
    bind(s, (struct sockaddr *)&sa, sizeof sa);
 
    int x = fork();
    if(x!=0) {
        return 0;
    }
 
    listen(s, BACKLOG);
 
    for(;;) {
        b = sizeof sa;
        if ((c = accept(s, (struct sockaddr *)&sa, &b)) < 0) {
            perror("daytimed accept");
            return 4;
        }
        client = fdopen(c,"w");
        t = time(NULL);
        tm = gmtime(&t);
        fprintf(client, "%.4i-%.2i-%.2iT%.2i:%.2i:%.2iZ\n",
        tm->tm_year + 1900,
        tm->tm_mon + 1,
        tm->tm_mday,
        tm->tm_hour,
        tm->tm_min,
        tm->tm_sec);
        fclose(client);
    }
}
In Action..
Korays-MacBook-Pro:socketclient koraytugay$ gcc hello.c
Korays-MacBook-Pro:socketclient koraytugay$ ./a.out
Korays-MacBook-Pro:socketclient koraytugay$ telnet localhost 5001
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
2015-04-28T20:25:59Z
Connection closed by foreign host.