🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4475

TWinSocketStream->Write problem

#4475
From: Eyyub Volkan �ektimur
Date: Thu, 27 Jan 2005 10:05
53 lines
3070 bytes
Hi,

my server is "stThreadBlocking" and client is "ctBlocking". I receive data
in threads by controlling the Socket via TWinSocketStream. (on both side).
I'm using TWinSocketStream to send & receive data, the problem is at "Write"
method of TWinSocketStream. As you know Write method returns number of bytes
writen. So i wrote a loop that controls this result and if the result is
smaller than MemorySize (need to send) , then i try to send the remaining
part again. Something like this;

-----------------------------------------------------------
 DataSize : size of data to send
 WriteMemory=(char*)Data;            // Memory to write
 WritenBytes=0;

 while (WritenBytes!=DataSize && TimeOut<PxMultiUserProtocol_TimeOut0)
       {

WritenBytes+=SocketStream->Write((WriteMemory+(int)WritenBytes),DataSize-Wri
tenBytes);

       if (WritenBytes!=DataSize)
          {
          // wait a moment
          Sleep(250);
          }
    ...
    ...
    ...
       }

-----------------------------------------------------------

everything seems ok.  but when Write method returns smaller than DataSize
(especially 0) , and the package re-writen , client side reads this package
twice , supposing that server side writen this package twice but server side
tried to write package and write method returned 0 so server side write this
package again. this situation does not hapen everytime or for every package.
Anyway client read more bytes than server sent. i don't know the packages
protect their order or they are mixed... but at the last of hours of
debugging, i found that client receives more than server sent. for example
server totally sent 239782 bytes but client received 278522 bytes. The total
bytes of server tried to sent is also 278522 (but succeded sent bytes is
239782).

i couldn't understand this ? Write method have a bug or am i understanding
something wrong ???

thanks for help...
________________________________________
Eyyub Volkan �ektimur
Proya Software & Trade Inc.
Head of Core Development Department
Technical Details
Message-ID: <41f8bc22@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.zanker.org!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,4dfffaaf64791146,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII
From: "Eyyub Volkan �ektimur" <evcektimur@prokon.com.tr>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: TWinSocketStream->Write problem
Date: Thu, 27 Jan 2005 12:05:05 +0200
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 213.232.9.2
Message-ID: <41f8bc22@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1106820130 213.232.9.2 (27 Jan 2005 02:02:10 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.zanker.org!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail