socket broken pipe error on sending huge data.
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > socket broken pipe error on sending huge data.




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    socket broken pipe error on sending huge data.  
rohit


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-16-07 06:20 PM

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;
}






[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
David Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-17-07 12:20 AM

On Jul 16, 10:23 am, rohit <PowerPCDevelo...@gmail.com> wrote:
> 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

Short version -- the 'read' needs to be in a 'while' loop. You need to
keep reading until you get all the data. If you stop after you get one
bit of data, the server will soon be sending to nothing.

DS






[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-17-07 12:20 AM

On Mon, 16 Jul 2007 17:23:20 -0000, rohit
<PowerPCDeveloper@gmail.com> wrote:
>
>
> 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///

A broken pipe error means the receiving process died.  Maybe you could
use strace or some other tool to find out why.


--
Using TSO is like kicking a dead whale down the beach.
-- S. C. Johnson





[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
Igmar Palsenberg


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-17-07 12:21 PM

rohit wrote:
> 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.

In short : You can't assume that writing or reading (large) amounts of
data in one read() / write() call succeeds.




Igmar





[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
rohit


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-18-07 06:23 AM

Thanks, b/w can we use UDP i.e datagrams to send huge amounts (approx
2MB) of data per transaction continously?
Rohit
On Jul 17, 12:50 pm, Igmar Palsenberg <ig...@palsenberg.local> wrote:
> rohit wrote: 
> 
>
> In short : You can't assume that writing or reading (large) amounts of
> data in one read() / write() call succeeds.
>
>         Igmar







[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
Ian Collins


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-18-07 06:23 AM

rohit wrote:

Please don't top-post.

> On Jul 17, 12:50 pm, Igmar Palsenberg <ig...@palsenberg.local> wrote: 
> Thanks, b/w can we use UDP i.e datagrams to send huge amounts (approx
> 2MB) of data per transaction continously?
> Rohit

Not reliably unless you add your own higher layer protocol over UDP.

--
Ian Collins.





[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-18-07 06:23 AM

In article <1184730709.367083.129570@j4g2000prf.googlegroups.com>,
rohit <PowerPCDeveloper@gmail.com> wrote:

> Thanks, b/w can we use UDP i.e datagrams to send huge amounts (approx
> 2MB) of data per transaction continously?

The maximum size of a UDP datagram is 64K bytes, including the UDP
header.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***





[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
David Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-18-07 12:23 PM

On Jul 17, 12:50 am, Igmar Palsenberg <ig...@palsenberg.local> wrote:

> In short : You can't assume that writing or reading (large) amounts of
> data in one read() / write() call succeeds.

Although in this case, it does succeed. It just doesn't read as much
data as he might like.

DS






[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
rohit


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-19-07 06:20 PM

On Jul 18, 12:33 pm, David Schwartz <dav...@webmaster.com> wrote:
> On Jul 17, 12:50 am, Igmar Palsenberg <ig...@palsenberg.local> wrote:
> 
>
> Although in this case, it does succeed. It just doesn't read as much
> data as he might like.
>
> DS

Please clarify for following: I want to send 1.5 MB of data from
server to client continously
(a)  So from the server part do i need to create a single buffer of
1.5 MB ? Or make small buffers from the server itself?
(b) Then at client end, do i need to allocate a small buffer area,
lets say 100 KB each, keep on getting the data and add in my 1.5MB
buffer ? Till i read all the data?

As posted in previous post, I am a novice in socket programming area,
so all comments, code snippet, knowledge sharing things are most
welcome.






[ Post a follow-up to this message ]



    Re: socket broken pipe error on sending huge data.  
rohit


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-19-07 06:20 PM

On Jul 18, 12:33 pm, David Schwartz <dav...@webmaster.com> wrote:
> On Jul 17, 12:50 am, Igmar Palsenberg <ig...@palsenberg.local> wrote:
> 
>
> Although in this case, it does succeed. It just doesn't read as much
> data as he might like.
>
> DS

Also, how can I know in advance how much amount of data a socket can
read or write ?






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:00 PM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register