#include #include #include #include #include int main(){ int sockfd, ptrlen, childpid,i; char *ptr="hello socket world\n"; char ptd[512]; struct sockaddr_in serv_addr; bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); serv_addr.sin_port = htons(5000); if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) perror("socket error"); if(connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("connect error"); ptrlen = strlen(ptr); write(sockfd, ptr, ptrlen) ; printf("%s\n",ptr); read(sockfd, ptd, 512); printf("%s\n",ptd); return 0; }