Multiple send()'s

Thread Tools Search this Thread
Top Forums Programming Multiple send()'s
# 1  
Old 12-30-2007
Multiple send()'s

Hi guys I'm quite new to socket programming. I'm using Beej's guide.

I have a program that requests a html page and downloads it one character at a time stopping when it reaches an EOF. I do this with the send() and recv() functions. When I'm finished I use send() again to get another page but I instantly get a EOF back. Both pages are working.

I'm not sure what i'm missing and would appreciate if any one could help. Thanks in advance.

Edit Figured it now was using HTTP 1.0!

Last edited by seanword; 12-30-2007 at 11:21 AM..
# 2  
Old 12-30-2007
If you are using send and recv I don't see the point in testing for eof or reading data one character at a time. send and recv have perefectly reasonable ways to deal with data streams without the stdio constructs. The probable cause for your second page eof failure is a logic problem in testing for eof and/or that the recv hasn't read any data and the old data is still stored in memory. Don't know because you haven't posted sample code.

Here's a hacked up echo client with eof inclusions for an example of send and may help.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>

#define BSZ 25
#define EPORT 7

int makeConnect(char *);
void chomp(char *);
int iseofhere(char *);
void addeof(char *);

int main(int argc , char **argv) {
int s, err, p = 0;
char sbuf[BSZ];
char rbuf[BSZ];

                     if (argc != 2) {printf("Please provide a host ip address for connect().\n"); return 1;}
                     if ( (s = makeConnect(argv[1])) <= 0) {
                          return 1;

                     while (1) {
                               printf("\nSend string through descriptor %d: ",s);
                               if (strcmp(sbuf,"quit\n") == 0) {close(s); break;}
                               if ((p++) % 3 == 0) {addeof(sbuf);}
                               if ( (err = send(s,sbuf,BSZ,0)) <= 0) {perror("send()"); continue;}
                               if ( (err = recv(s,rbuf,BSZ,0)) <= 0) {perror("recv()"); continue;}
                               if (iseofhere(sbuf) || iseofhere(rbuf)) {printf("Detected eof.\n");}
                               chomp(sbuf); chomp(rbuf);
                               printf("Sent buffer %s and received buffer %s\n",sbuf,rbuf);
return 0;

void addeof(char *dta) {
int p = strlen(dta);
                        dta[(int)(1 + rand() %  p)] = EOF;

int iseofhere(char *dta) {
                         for ( ; *dta != '\0' ; dta++) {
                             if (*dta == EOF) {return 1;}
                          return 0;

void chomp(char *dta) {

                      for ( ; *dta != '\n' && *dta != '\0'; dta++) {;}
                      *dta = '\0';

int makeConnect(char *addr) {
int sck = -1;
in_addr_t valid_add;
struct sockaddr_in info;

                             if ( (valid_add = inet_addr(addr)) < 0) {return sck;}
                             if ( (sck = socket(PF_INET,SOCK_STREAM,0)) < 0) {return sck;}

                             info.sin_port = htons(EPORT);
                             info.sin_addr.s_addr = valid_add;
                             info.sin_family = PF_INET;
                             if (connect(sck,(struct sockaddr *)&info,sizeof(info)) < 0) {
                                 return -1;
                             return sck;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send a mail to multiple users

I have a file 1.txt which has 3 mail ids as below: Now I want to write a script which will read this file and send the mail to all the users present in this file. (6 Replies)
Discussion started by: Vivekit82
6 Replies

2. Red Hat

How to send mail with multiple attachments?

We don't have uuencode installed in our machines..... Please tell me how to send mail with multiple attachments ??? URGENT !!!!! Please tell me using command line (or) scripts.......... please...... Thanks in Advance.... (1 Reply)
Discussion started by: vamshigvk475
1 Replies

3. Shell Programming and Scripting

How to send email with multiple attachments ?

Hello , I am trying to send an email with two attachments . I have tried all previous suggestion in this forum but none worked. I could send one attachment in an email by uuencode $file "$file" | mailx -m -s "File" but unable to send multiple attachments . I have tried ... (8 Replies)
Discussion started by: RaviTej
8 Replies

4. Shell Programming and Scripting

Grep multiple instances and send email.

Removed (15 Replies)
Discussion started by: saisneha
15 Replies

5. Shell Programming and Scripting

how to send multiple files from the shell script

hi, how to send multiple files from the shell script eg : i have /home/adm/file1 /home/adm/file2 /home/adm/cfg how can i attach these files in the mail ? (1 Reply)
Discussion started by: mail2sant
1 Replies

6. AIX

Not able to send out multiple file in mail

Hi All, I have AIX 5.3 server. I am not able to transfer multiple file in mail but I can send one file at a time. the following command I am using to send multiple file mail -s 'PICS EXP RATE Logs' < /data02/transfer/*_experience_rate_log.txt but this not working. i can send... (2 Replies)
Discussion started by: vishalpatel03
2 Replies

7. UNIX for Dummies Questions & Answers

to send email to multiple users

hi, i'm pretty new to this unix. i've been asked to create a shell script which will pick up the email id from a text file(stored in same machine, same directory) searches for that id in another file in which a product name( a one line text) is mentioned against it. then it should send a mail... (0 Replies)
Discussion started by: vishwas.shenoy
0 Replies

8. Shell Programming and Scripting

Using mailx to send email to multiple users.

Hi, I am using the mailx command to send email to multple users. The command works fine when i am sending mail to a single user but when i insert multiple email ids inside the quote it does not work. All the email ids are coming from a property file.Please have a lookt at the property file and... (4 Replies)
Discussion started by: priyaksingh
4 Replies

9. Shell Programming and Scripting

Need to send multiple files during ftp

Hi guys... I'm working on #!/bin/sh script in a Solaris 7 box that should send several files over to another machine via FTP. Here's what the script looks like: # This script will send the daily MSP customer counts # to the Crystal Reports server located at cd... (2 Replies)
Discussion started by: cdunavent
2 Replies

10. UNIX for Dummies Questions & Answers

How to send mail to multiple users ???

Hi All, How to send mails to multiple users using a single mailx command. Urgently require help Thanks in advance Rgds Arunava (3 Replies)
Discussion started by: arunava_maity
3 Replies
Login or Register to Ask a Question