# Include "fun. H"
Int main (INT argc, char ** argv)
{
Int sockfd, L;
Struct sockaddr_in servaddr;
Char Buf [1024];
Sockfd = socket (pf_inet, sock_stream, 0 );
Printf ("socket OK/N ");
Bzero (& servaddr, sizeof (servaddr ));
Servaddr. sin_family = pf_inet;
Servaddr. sin_addr.s_addr = inet_addr ("192.168.1.135 ");
Servaddr. sin_port =Htons(8882 );
If (connect (sockfd, (struct sockaddr *) & servaddr, sizeof (servaddr) <0)
{
Perror ("Connect ");
Return-1;
}
L = read (sockfd, Buf, sizeof (BUF ));
Buf [l] = 0;
Printf ("% s/n", Buf );
Close (sockfd );
}
the above is just a simple tcp client Program , but because I didn't write htons (converts a 16-bit integer host to a network byte), CONNECT: Connection refused, when I read the book htons (inaddr_any) , htons is optional. I think it is also dispensable in this place, and the results lead to logical errors. The Details determine success or failure;