![]() |
| | #1 |
| Guest
Posts: n/a
| socket programming recv function char buffer[32]; SOCKET sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); struct sockaddr_in * address= new (struct sockaddr_in); address->sin_family=AF_INET; address->sin_addr.s_addr=inet_addr("192.168.0.1"); address->sin_port=htons(80); memset(address->sin_zero,'\0',8); printf("connect %d \n",connect(sock,(struct sockaddr *)address,sizeof(*address))); printf("%d ",send(sock,"GET /index.htm",14,0)); recv(sock,buffer,32,0); till send everything is working fine but why i am not able to retreive the index.htm page back . i have tried the same program on my linux box too but to no avail .what is the prob am i missing something ... |
|
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,700
| > printf("%d ",send(sock,"GET /index.htm",14,0)); Do you need to send a newline with this as well? > recv(sock,buffer,32,0); This doesn't know how much data will be returned, and in particular, it can return the data in fragments. It's up to you to reassemble the data into its proper form. Code: int n;
while ( (n=recv(sock,buffer,32,0)) > 0 ) {
// do something with n bytes in buffer
}
if ( n == -1 ) {
perror( "cant recv" );
}
|
| Salem is offline | |
| | #3 |
| Guest
Posts: n/a
| thanx it's working now ... i needed two new line characters .... |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling sample DarkGDK Program | Phyxashun | Game Programming | 6 | 01-27-2009 03:07 AM |
| shutdown function socket programming | 256Doofus | Networking/Device Communication | 0 | 10-26-2008 04:47 AM |
| How to fix misaligned assignment statements in the source code? | biggyK | C++ Programming | 28 | 07-16-2006 11:35 PM |
| Dikumud | maxorator | C++ Programming | 1 | 10-01-2005 06:39 AM |
| I need help with passing pointers in function calls | vien_mti | C Programming | 3 | 04-24-2002 10:00 AM |