Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mailrus!iuvax!cica!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!crdgw1!ge-dab!puma!andrew.ATL.GE.COM!jnixon From: jnixon@andrew.ATL.GE.COM (John F Nixon) Newsgroups: comp.unix.wizards Subject: Re: TCP socket using BSD recv() (WIN/TCP for VMS) Message-ID: <232@puma.ge.com> Date: 20 Mar 90 00:42:26 GMT References: <22791@adm.BRL.MIL> Sender: news@puma.ge.com Lines: 34 TAYBENGH%NUSDISCS.BITNET@cunyvm.cuny.edu writes: > I faced the similar problem as King when I used BSD recv() provided by >WIN/TCP for VMS Release 3.2. The maximum size received is only 4K for TCP. >But one thing puzzled me is I always get 1K in the very first recv() call, >only then I receive the remaining data, if the buffer size sent > 1K. For >example, if the client sends 5K of data, then the server's first recv() call >get 1K, and the second recv() will get the remaining 4K. It sounds like you are using SOCK_STREAM sockets. The semantics of SOCK_STREAM are such that you are *not* guaranteed to receive all the bytes of a write with a single read (especially with "large" writes). You are responsible for maintaining record boundaries with SOCK_STREAM sockets. Either write fixed size records (usually not advisable), or prepend a size field to your records. Then read in a loop till all of the data arrives. Pseudo-code is: /* record size in recsize */ byteshere = 0; while ( byteshere < recsize ) { bytes = read (soc, buf + byteshere, recsize - byteshere); if ( bytes < 0 ) { error stuff... } byteshere += bytes; } You get the idea... -- ---- jnixon@atl.ge.com ...steinmetz!atl.decnet!jnxion