繁星点点滴滴
与一般通讯一样。需要编写发送端(客户)和接收端(服务)的程序。发送端// 任务 1: 建一个可靠的stream TCP socket.if ((sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP))==INVALID_SOCKET){printf("Can not create socket.\n"); exit(0);}// 任务 2: 双方连接addr.sin_family = PF_INET;// u_short htons (u_short hostshort );// convert byte order from host to network order// FTP 通讯口 20,21, HTTP通讯口 80, telnet 通讯口 23addr.sin_port = htons(SERVER_PORT);if ((addr.sin_addr.s_addr=inet_addr(url))==-1){if ((hs=gethostbyname(url))==NULL){id = WSAGetLastError();switch (id)。。。}memcpy((void *)&addr.sin_addr.s_addr,hs->h_addr,hs->h_length);if (connect(sock,(LPSOCKADDR)&addr,sizeof(addr))==SOCKET_ERROR){。。}// task 3: 通讯if (send(sock,buff,strlen(buff),0) != strlen(buff)) printf("client send error \n");。。。if (recv(sock,buff,sizeof(buff),0) == SOCKET_ERROR){。。。}。。。