Little problem with C program
- From: Elekaj <elekaj34@xxxxxxx>
- Date: Sun, 28 Aug 2005 19:42:52 +0200
Hello,
This is my problem, the function listed under this text does'nt seems to work correctly.
void requestHTTP(char *port, char *adress, char *request)
{
int cddbPort,cddbSocket;
char response[MAX_CHAR];
struct sockaddr_in addr;
struct hostent *hp;
cddbPort = atoi(port);
cddbSocket = socket(AF_INET,SOCK_STREAM,0);
hp = gethostbyname((char *) adress);
if ( hp == NULL ) {
printf("ERREUR: Nom de serveur inconnu !!!\n");
exit(EXIT_FAILURE);
}
addr.sin_family = AF_INET;
addr.sin_port = htons(cddbPort);
memcpy(&(addr.sin_addr),hp->h_addr,sizeof(hp->h_addr));/* Connection au serveur décrit dans addr via la socket.*/
printf("Connecting to server ...\n");
if ( connect(cddbSocket,((struct sockaddr * )&addr),sizeof(addr)) == -1 ) {
printf("ERROR: Unable to connect to server\n");
exit(EXIT_FAILURE);
}
printf("Sending request : %s\n",request);
send(cddbSocket,&request,sizeof(request),0);
printf("Reading response ...\n");
read(cddbSocket,&response,sizeof(response));
printf("Response : %s",response);
shutdown(cddbSocket,SHUT_RDWR);
close(cddbSocket);
}
When I call the function requestHTTP("80","192.168.0.1","GET\n"), the function works fine until the read command (on the screen, there are the message "Reading response ..." and nothing else appens.
If I try to connect to my HTTP server with telnet 192.168.0.1 80 , when I type GET and enter, the server give the awaited response.
So I think that there are a bug in my function but I don't see where.
Is it possible to have little help ?
Thanks
Elekaj .
- Follow-Ups:
- Re: Little problem with C program
- From: Phlip
- Re: Little problem with C program
- Prev by Date: Re: GNU Public Licences Revisited (again)
- Next by Date: Re: C++ API for files & directory manipulation
- Previous by thread: C++ API for files & directory manipulation
- Next by thread: Re: Little problem with C program
- Index(es):