/* NAME: tcpServer0 SYNOPSIS: tcpServer0 DESCRIPTION: The program creates a tcp socket in the inet domain, binds it to port 10345, listen and accept a connection from tcpClient0, and receives any message arrived to the socket and prints it out */ #include "def" void exit(int); main(int argc, char** argv) { int sd, psd; struct sockaddr_in name; char buf[1024]; int cc; sd = socket (AF_INET,SOCK_STREAM,0); name.sin_family = AF_INET; name.sin_addr.s_addr = htonl(INADDR_ANY); name.sin_port = htons(atoi(argv[1])); bind( sd, (SA *) &name, sizeof(name) ); listen(sd,1); psd = accept(sd, 0, 0); for(;;) { cc=recv(psd,buf,sizeof(buf), 0) ; if (cc == 0) exit (0); buf[cc] = NULL; printf("message received: %s\n", buf); } }