C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-29-2001, 01:17 AM   #1
vicky
Guest
 
Posts: n/a
socket programming recv function

on my lan 192.168.0.1 is running a webserver so when i wrote a simple socket application like



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 ...
  Reply With Quote
Old 10-29-2001, 03:04 AM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
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" );
}
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 10-29-2001, 03:39 AM   #3
vicky
Guest
 
Posts: n/a
thanx it's working now ... i needed two new line characters ....
  Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 07:05 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22