maximum receiving data in stream socket

maximum receiving data in stream socket

Post by Rober » Thu, 20 Jul 2000 04:00:00



Hi

Why I can send 5000 bytes data ( bigger than 1448  ) from my client, but in
the server side I only receive 1448 bytes. My client server program  use
TCP socket.

I know that TCP socket wont allow data bigger than 1500 Kbytes, but why it
is possible to send bigger amount of data and not receive it.

I use write(sockfd,buf,strlen(buf)); to send data, and
recv(newsockfd,buffer,5000,0)) for receiving data.

I dont know how could I read the rest of data, what is happening to them ?
In tcpdump I can see, I have sent 5000 bytes but in my server program I only
get 1448 using recv.
Could it be I do some thing wrong  ? Or it is not posible.

Thanks Robert

Here is my code for server

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#define mesage
void error(char *msg)
{
    perror(msg);
    exit(1);

Quote:}

int main(int argc, char *argv[])
{
     int sockfd, newsockfd, portno, clilen;
     char buffer[5000];
     struct sockaddr_in serv_addr, cli_addr;
     int n, i ;
     i = 0;
     if (argc < 2) {
         fprintf(stderr,"ERROR, no port provided\n");
         exit(1);
     }
     sockfd = socket(AF_INET, SOCK_STREAM, 0);
     if (sockfd < 0)
        error("ERROR opening socket");
     bzero((char *) &serv_addr, sizeof(serv_addr));
     portno = atoi(argv[1]);
     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,10);
     bzero(buffer,5000);

    while(1){
    clilen = sizeof(cli_addr);
    newsockfd = accept(sockfd,(struct sockaddr *) &cli_addr,&clilen);
    if (newsockfd < 0){
          error("ERROR on accept");
          exit(0);
    }
    i++;
   if((n=recv(newsockfd,buffer,5000,0))==-1)
      {
            perror("recv");
            exit(1);
      }
     printf("Here is the %d message: %s\n",i,buffer);
     printf("Here is the %d message with length %d\n",i,strlen(buffer));
     }

Quote:}

 
 
 

maximum receiving data in stream socket

Post by Barry Margoli » Thu, 20 Jul 2000 04:00:00




>Hi

>Why I can send 5000 bytes data ( bigger than 1448  ) from my client, but in
>the server side I only receive 1448 bytes. My client server program  use
>TCP socket.

>I know that TCP socket wont allow data bigger than 1500 Kbytes, but why it
>is possible to send bigger amount of data and not receive it.

>I use write(sockfd,buf,strlen(buf)); to send data, and
>recv(newsockfd,buffer,5000,0)) for receiving data.

>I dont know how could I read the rest of data, what is happening to them ?
>In tcpdump I can see, I have sent 5000 bytes but in my server program I only
>get 1448 using recv.
>Could it be I do some thing wrong  ? Or it is not posible.

Since TCP is a byte stream protocol, not a message protocol, it doesn't
remember the size of the message you sent.  Each call to recv() can return
any amount of data.  You have to call recv() repeatedly until you get it
all.

--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

maximum receiving data in stream socket

Post by Jürgen Griga » Fri, 28 Jul 2000 04:00:00


The recv returns when the first data are ready to be read. So, whenever I send
data over TCP/IP I use a small application protocol. This contains at least a
header of 4 Bytes, containing the length of the whole message. The receiver
reads first this header and then, in a loop, the rest of the data.
This works fine for over ten years now and on every platform.

I hope this helps

Robert schrieb:

Quote:> Hi

> Why I can send 5000 bytes data ( bigger than 1448  ) from my client, but in
> the server side I only receive 1448 bytes. My client server program  use
> TCP socket.

> I know that TCP socket wont allow data bigger than 1500 Kbytes, but why it
> is possible to send bigger amount of data and not receive it.

> I use write(sockfd,buf,strlen(buf)); to send data, and
> recv(newsockfd,buffer,5000,0)) for receiving data.

> I dont know how could I read the rest of data, what is happening to them ?
> In tcpdump I can see, I have sent 5000 bytes but in my server program I only
> get 1448 using recv.
> Could it be I do some thing wrong  ? Or it is not posible.

> Thanks Robert

> Here is my code for server

> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <unistd.h>
> #include <netinet/in.h>
> #define mesage
> void error(char *msg)
> {
>     perror(msg);
>     exit(1);
> }
> int main(int argc, char *argv[])
> {
>      int sockfd, newsockfd, portno, clilen;
>      char buffer[5000];
>      struct sockaddr_in serv_addr, cli_addr;
>      int n, i ;
>      i = 0;
>      if (argc < 2) {
>          fprintf(stderr,"ERROR, no port provided\n");
>          exit(1);
>      }
>      sockfd = socket(AF_INET, SOCK_STREAM, 0);
>      if (sockfd < 0)
>         error("ERROR opening socket");
>      bzero((char *) &serv_addr, sizeof(serv_addr));
>      portno = atoi(argv[1]);
>      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,10);
>      bzero(buffer,5000);

>     while(1){
>     clilen = sizeof(cli_addr);
>     newsockfd = accept(sockfd,(struct sockaddr *) &cli_addr,&clilen);
>     if (newsockfd < 0){
>           error("ERROR on accept");
>           exit(0);
>     }
>     i++;
>    if((n=recv(newsockfd,buffer,5000,0))==-1)
>       {
>             perror("recv");
>             exit(1);
>       }
>      printf("Here is the %d message: %s\n",i,buffer);
>      printf("Here is the %d message with length %d\n",i,strlen(buffer));
>      }
> }

--
====================================================================
Juergen Grigat                  Tel.: +49 7541 282 - 347
                                Fax : +49 7541 282 - 299

Avitech
Aviation Management Technologies GmbH

Jrgen Grigat
Abt. SWE
Bahnhofplatz 1
Postfach 1430
D 88004 Friedrichshafen

====================================================================

 
 
 

maximum receiving data in stream socket

Post by Jürgen Griga » Fri, 28 Jul 2000 04:00:00


The recv returns when the first data are ready to be read. So, whenever I send
data over TCP/IP I use a small application protocol. This contains at least a
header of 4 Bytes, containing the length of the whole message. The receiver
reads first this header and then, in a loop, the rest of the data.
This works fine for over ten years now and on every platform.

I hope this helps

Robert schrieb:

Quote:> Hi

> Why I can send 5000 bytes data ( bigger than 1448  ) from my client, but in
> the server side I only receive 1448 bytes. My client server program  use
> TCP socket.

> I know that TCP socket wont allow data bigger than 1500 Kbytes, but why it
> is possible to send bigger amount of data and not receive it.

> I use write(sockfd,buf,strlen(buf)); to send data, and
> recv(newsockfd,buffer,5000,0)) for receiving data.

> I dont know how could I read the rest of data, what is happening to them ?
> In tcpdump I can see, I have sent 5000 bytes but in my server program I only
> get 1448 using recv.
> Could it be I do some thing wrong  ? Or it is not posible.

> Thanks Robert

> Here is my code for server

> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <unistd.h>
> #include <netinet/in.h>
> #define mesage
> void error(char *msg)
> {
>     perror(msg);
>     exit(1);
> }
> int main(int argc, char *argv[])
> {
>      int sockfd, newsockfd, portno, clilen;
>      char buffer[5000];
>      struct sockaddr_in serv_addr, cli_addr;
>      int n, i ;
>      i = 0;
>      if (argc < 2) {
>          fprintf(stderr,"ERROR, no port provided\n");
>          exit(1);
>      }
>      sockfd = socket(AF_INET, SOCK_STREAM, 0);
>      if (sockfd < 0)
>         error("ERROR opening socket");
>      bzero((char *) &serv_addr, sizeof(serv_addr));
>      portno = atoi(argv[1]);
>      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,10);
>      bzero(buffer,5000);

>     while(1){
>     clilen = sizeof(cli_addr);
>     newsockfd = accept(sockfd,(struct sockaddr *) &cli_addr,&clilen);
>     if (newsockfd < 0){
>           error("ERROR on accept");
>           exit(0);
>     }
>     i++;
>    if((n=recv(newsockfd,buffer,5000,0))==-1)
>       {
>             perror("recv");
>             exit(1);
>       }
>      printf("Here is the %d message: %s\n",i,buffer);
>      printf("Here is the %d message with length %d\n",i,strlen(buffer));
>      }
> }

--
====================================================================
Juergen Grigat                  Tel.: +49 7541 282 - 347
                                Fax : +49 7541 282 - 299

Avitech
Aviation Management Technologies GmbH

Jrgen Grigat
Abt. SWE
Bahnhofplatz 1
Postfach 1430
D 88004 Friedrichshafen

====================================================================

 
 
 

maximum receiving data in stream socket

Post by Jürgen Griga » Fri, 28 Jul 2000 04:00:00


The recv returns when the first data are ready to be read. So, whenever I send
data over TCP/IP I use a small application protocol. This contains at least a
header of 4 Bytes, containing the length of the whole message. The receiver
reads first this header and then, in a loop, the rest of the data.
This works fine for over ten years now and on every platform.

I hope this helps

Robert schrieb:

Quote:> Hi

> Why I can send 5000 bytes data ( bigger than 1448  ) from my client, but in
> the server side I only receive 1448 bytes. My client server program  use
> TCP socket.

> I know that TCP socket wont allow data bigger than 1500 Kbytes, but why it
> is possible to send bigger amount of data and not receive it.

> I use write(sockfd,buf,strlen(buf)); to send data, and
> recv(newsockfd,buffer,5000,0)) for receiving data.

> I dont know how could I read the rest of data, what is happening to them ?
> In tcpdump I can see, I have sent 5000 bytes but in my server program I only
> get 1448 using recv.
> Could it be I do some thing wrong  ? Or it is not posible.

> Thanks Robert

> Here is my code for server

> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <unistd.h>
> #include <netinet/in.h>
> #define mesage
> void error(char *msg)
> {
>     perror(msg);
>     exit(1);
> }
> int main(int argc, char *argv[])
> {
>      int sockfd, newsockfd, portno, clilen;
>      char buffer[5000];
>      struct sockaddr_in serv_addr, cli_addr;
>      int n, i ;
>      i = 0;
>      if (argc < 2) {
>          fprintf(stderr,"ERROR, no port provided\n");
>          exit(1);
>      }
>      sockfd = socket(AF_INET, SOCK_STREAM, 0);
>      if (sockfd < 0)
>         error("ERROR opening socket");
>      bzero((char *) &serv_addr, sizeof(serv_addr));
>      portno = atoi(argv[1]);
>      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,10);
>      bzero(buffer,5000);

>     while(1){
>     clilen = sizeof(cli_addr);
>     newsockfd = accept(sockfd,(struct sockaddr *) &cli_addr,&clilen);
>     if (newsockfd < 0){
>           error("ERROR on accept");
>           exit(0);
>     }
>     i++;
>    if((n=recv(newsockfd,buffer,5000,0))==-1)
>       {
>             perror("recv");
>             exit(1);
>       }
>      printf("Here is the %d message: %s\n",i,buffer);
>      printf("Here is the %d message with length %d\n",i,strlen(buffer));
>      }
> }

--
====================================================================
Juergen Grigat                  Tel.: +49 7541 282 - 347
                                Fax : +49 7541 282 - 299

Avitech
Aviation Management Technologies GmbH

Jrgen Grigat
Abt. SWE
Bahnhofplatz 1
Postfach 1430
D 88004 Friedrichshafen

====================================================================