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:wr
ite 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_ad
dr,
server->h_length);
serv_addr.sin_port = htons(5902);
if (connect(sockfd,&serv_addr
,sizeof(se
rv_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,size
of(HUGEDAT
A));
if (n < 0)
error("ERROR reading from socket");
}
return 0;
}
Start Free Trial