home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / bsd / 11806 < prev    next >
Encoding:
Text File  |  1993-01-25  |  1.6 KB  |  44 lines

  1. Newsgroups: comp.unix.bsd
  2. Path: sparky!uunet!ddssuprs!lpc
  3. From: lpc@dickens.com (Luis P Caamano)
  4. Subject: Re: Problem to transfer large data via socket communication - Need Help
  5. Message-ID: <1993Jan25.193306.22638@dickens.com>
  6. Date: Mon, 25 Jan 1993 19:33:06 GMT
  7. References: <1993Jan8.071612.13716@news.uni-stuttgart.de> <1829@igd.fhg.de>
  8. Organization: Dickens Data Systems, Inc.
  9. Lines: 33
  10.  
  11. In article <1829@igd.fhg.de> mike@igd.fhg.de (Mike Sokolewizc (Gast)) writes:
  12. >>  we develope a program with socket communication. We have large
  13. >>  datas to transfer. So we use the following routines
  14. >>  to send data from socket to socket (stream):
  15. >>
  16. >>        write(socket,(char*)data,buffer)
  17. >>        read(socket,(char*)data,buffer)
  18. >>
  19. >>  But now we've problems sending/receiving large data for
  20. >>  example 50*50*50 matrix of floats or larger. Is there any
  21. >>     Oliver
  22. >
  23. >the system gives you only exactly what's waiting at that socket at that instant, even if more
  24. >data is coming.  Therefore, you have to nest the read() within a loop and keep reading until
  25. >you get an error or the expected number of bytes:
  26. >
  27. >  num_read = 0;
  28. >  do
  29. >    {
  30. >      l = read( socket, &buffer[num_read], BUF_SIZE - num_read );
  31. >      num_read += l;
  32. >    }
  33. >  while ( (num_read < BUF_SIZE) && (l > 0) );
  34. >
  35.  
  36. Same thing applies for write() over a socket descriptor.
  37.  
  38. -- 
  39. Luis P. Caamano                        |         lpc@dickens.com
  40. Dickens Data Systems, Inc. Atlanta, GA |         uunet!dickens.com!lpc
  41. ---------------------------------------------------------------------------
  42. If I think I know it all, I'll stop learning. -myself
  43. The more I learn, the more I know I know nothing. -somebody else
  44.