Advertisement

07.16.2007 at 10:28AM PDT, ID: 22699297
[x]
Attachment Details

socket write broken pipe

Asked by rohitdivas in C Programming Language, Unix Systems Programming, Apple Networking

Tags: pipe, broken, socket, write

Dear All,
I have developed a simple client server application, the server needs
to send around 1.5 MB of data to the client for each transaction
continously. But the server is only able to send only 81660 bytes of
data and throws
"ERROR writing to socket: Broken pipe"

1) Cannot we send huge data through sockets and that too continously ?
2) What can be possible reason for this issue?
3) How to resolve the same?
4) Any code snippet will be of great use.
I am a NO expert in this area, so all comments are most welcome.
/////// SERVER CODE SNIPPET///
int serverConnection()
{
    int sockfd, newsockfd, portno, clilen;
    char buffer[256];

    struct sockaddr_in serv_addr, cli_addr;

        int n;

        sockfd = socket(AF_INET, SOCK_STREAM, 0);

        if (sockfd < 0)
       error("ERROR opening socket");

        bzero((char *) &serv_addr, sizeof(serv_addr));

        portno = 5902;

        serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port = htons(portno);

        if (bind(sockfd, (struct sockaddr *) &serv_addr,
             sizeof(serv_addr)) < 0)
             error("ERROR on binding");

        listen(sockfd,5);
    clilen = sizeof(cli_addr);

        newsockfd = accept(sockfd,
                (struct sockaddr *) &cli_addr,
                &clilen);

        if (newsockfd < 0)
         error("ERROR on accept");

        bzero(buffer,256);

        n = read(newsockfd,buffer,255);

        if (n < 0) error("ERROR reading from socket");

        printf("Here is the message: %s\n",buffer);


        do{
        fillBuffer
        n = write(newsockfd, &HUGEDATA,sizeof(HUGEDATA));
       if( n < 1 && errno != EINTR ) {
       error("ERROR writing to socket");
       return 0;
       }

       if( n == EINTR ) {
       fprintf(stdout,"SOAP:\t:write interupted...tyring again");
       continue;
       }


    }while(1);

        if (n < 0) error("ERROR writing to socket");
    return 0;

}
///////////
////////////////CLIENT SNIPPET///
int receivedData()
{
 int sockfd,  n;
   struct sockaddr_in serv_addr;
   struct hostent *server;

   char buffer[256];

   sockfd = socket(AF_INET, SOCK_STREAM, 0);
   if (sockfd < 0)
       error("ERROR opening socket");
       server = gethostbyname("localhost");

   if (server == NULL) {
       fprintf(stderr,"ERROR, no such host\n");
       exit(0);
   }

   bzero((char *) &serv_addr, sizeof(serv_addr));
   serv_addr.sin_family = AF_INET;
   bcopy((char *)server->h_addr,
        (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
   serv_addr.sin_port = htons(5902);
   if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0)
       error("ERROR connecting");


       printf("Please enter the message: ");
   bzero(buffer,256);
       strcpy(buffer,"rohit");
   n = write(sockfd,buffer,strlen(buffer));
   if (n < 0)
        error("ERROR writing to socket");
  while(1)
  {
  n = read(sockfd,&HUGEDATA,sizeof(HUGEDATA));
       if (n < 0)
        error("ERROR reading from socket");

       }

   return 0;
}
Start Free Trial
[+][-]07.16.2007 at 10:54AM PDT, ID: 19497891

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C Programming Language, Unix Systems Programming, Apple Networking
Tags: pipe, broken, socket, write
Sign Up Now!
Solution Provided By: Anthony2000
Participating Experts: 4
Solution Grade: A
 
 
[+][-]07.16.2007 at 05:30PM PDT, ID: 19501308

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.17.2007 at 01:00AM PDT, ID: 19502884

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.17.2007 at 10:56AM PDT, ID: 19507248

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2007 at 01:25PM PDT, ID: 19508664

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.18.2007 at 02:52PM PDT, ID: 19517648

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32