日期:2014-05-16 浏览次数:20791 次
int main() { int clientfd; int n; char buf[BUFFSIZE]; struct sockaddr_in saddr; clientfd = my_socket(AF_INET, SOCK_STREAM, 0); bzero(buf,BUFFSIZE); bzero(&saddr, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_port = htons(S_PORT); inet_pton(AF_INET, "127.0.0,1", &saddr.sin_addr); my_connect(clientfd, (struct sockaddr *)&saddr, sizeof(saddr)); while(fgets(buf, BUFFSIZE, stdin)!= NULL) { my_write(clientfd, buf, sizeof(buf)); printf(" n : \n"); if (!(n = my_read(clientfd, buf, BUFFSIZE))) puts(" Sorry, the server has been closed..\n"); else printf(" m : \n"); my_write(STDOUT_FILENO, buf, n); bzero(buf,BUFFSIZE); } return 0; }