Topic: The client the translator

Kind time of days! I since the childhood do not digest a network but where without them, the client of the translator on  that was more cheerfully therefore decided to write. Took the code of the client from man 3 getaddrinfo, it seems. Actually, the code: int main (int argc, char ** argv) {const char* addr = "www.translate.yandex.ru"; struct addrinfo hints; struct addrinfo* result; int s=0, sfd=0, cr=0; memset (&hints, 0, sizeof (struct addrinfo)); hints.ai_family=AF_UNSPEC; hints.ai_socktype=SOCK_STREAM; hints.ai_flags=AI_PASSIVE | AI_CANONNAME; s=getaddrinfo (addr, NULL, &hints, &result); if (s! =0) {fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s)); exit (EXIT_FAILURE);} else {struct addrinfo* ai=result; for (ai=result; ai! =NULL; ai=ai-> ai_next) {if (ai-> ai_canonname! =NULL) printf ("%s\n", ai-> ai_canonname); sfd=socket (ai-> ai_family, ai-> ai_socktype, 0); if (sfd ==-1) continue; printf ("socket - [OK] \n");; cr=connect (sfd, ai-> ai_addr, ai-> ai_addrlen); printf ("connect result: %d\n", cr); if (cr! =-1) break; close (sfd);} if (ai == NULL) {fprintf (stderr, "Could not connect\n"); freeaddrinfo (result); close (sfd); exit (EXIT_FAILURE);} printf ("connect - [OK] \n");;} freeaddrinfo (result); close (sfd); return 0;} Anything yet does not do. Whether what connects only at SOCK_DGRAM and if in getaddrinfo to transfer NULL in the second parameter it is connected also type of connection SOCK_DGRAM is normal? If in hints to inscribe SOCK_STREAM on connect () hangs for some time, and then returns-1. I checked on different hosts. On http the connection on UDP fulfills, on https does not work generally. In what I am wrong, besides, that started to write a web client on ? Thanks!


Re: The client the translator

Hello, plastictown, you wrote: P> In what I am wrong, besides, that started to write a web client on ? Begin with learning of docks on sockets. Everything that you wrote is chewed and chewed time and again directly there. Even to ask it is necessary nobody - all there explicitly and it is accurately classified.