🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Problem with sending data with TCS/TSS (data has been received mixed and/or damaged)

#5363
From: Remy Lebeau (TeamB)
Date: Fri, 20 Aug 2004 18:26
49 lines
2438 bytes
"Vladimir Stefanovic" <spam@not.needed> wrote in message
news:41260071@newsgroups.borland.com...

> I just do not know yet the best way to inform the
> server of the expecting data size.

Just write the data's size to the socket before writing the actual data, and
then read the size before reading the data, ie:

    int size = the data size;
    ...->SendBuf(&size, sizeof(int));
    ...->SendBuf(buffer, size);

    //...

    void __fastcall TLanServerThread::ClientExecute()
    {
        TWinSocketStream *Stream = new TWinSocketStream(ClientSocket, 5000);
        try
        {
            while( (!Terminated) && (ClientSocket->Connected) )
            {
                if( Stream->WaitForData (5000) )
                {
                    int size = 0;
                    if( !ReadData(Stream, &size, sizeof(int)) )
                        break;

                    char *buffer = new char[size];
                    try
                    {
                        if( ReadData(Stream, buffer, size) )
                            // use your buffered data as needed...
                    }
                    __finally {
                        delete[] buffer;
                    }
                }
            }
        }
        __finally
        {
            delete Stream;
        }
    }


Gambit
Technical Details
Message-ID: <4126422a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41245031$1@newsgroups.borland.com> <4124d7ab@newsgroups.borland.com> <4124f2ca@newsgroups.borland.com> <4125baa0$1@newsgroups.borland.com> <41260071@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,9d2d5d657ea2710a
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <41245031$1@newsgroups.borland.com> <4124d7ab@newsgroups.borland.com> <4124f2ca@newsgroups.borland.com> <4125baa0$1@newsgroups.borland.com> <41260071@newsgroups.borland.com>
Subject: Re: Problem with sending data with TCS/TSS (data has been received mixed and/or damaged)
Date: Fri, 20 Aug 2004 11:26:31 -0700
Lines: 51
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: 68.69.17.41
Message-ID: <4126422a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1093026346 68.69.17.41 (20 Aug 2004 11:25:46 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail