🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Reading data from TServerSocket in TClientSocket

#2972
From: Bob Gonder
Date: Sun, 01 Jan 2006 03:45
44 lines
2204 bytes
Maurice Anderson wrote:

>However, when trying to read data from TScoket to the ClientSocket, it does
>not work.  Here is the code I put in the ClientSocket->OnRead event:
>
>void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
>      TCustomWinSocket *Socket)
>{
>
>   const int BytesToReceive = Socket->ReceiveLength();
>   if( BytesToReceive <= 0 )
>            return;
>
>  Memo1->Lines->Add("Server Transmitting: ");

That's on the main form?
I think you are supposed to Synchronize() with the main thread first.

>  TMemoryStream *ServerData = new TMemoryStream;
>  char *Buffer[256];

First, should be
  char Buffer[256];

Second, 256 is probably too small.
Should be larger than BytesToReceive.

	char * Buffer = new char[BytesToReceive];

>  Socket->ReceiveBuf(Buffer, BytesToReceive);

	delete[] Buffer;

>(2) Is ClientSocket->OnRead executed in a seperate thread?

Yes, usually.

>  (3) If not, is it wise to execute a client read in a seperate thread?

Yes.

>  (4) And if so, how do I accomplish that?

Use the OnRead event.
Technical Details
Message-ID: <thjer1h3bk668mqjsldbil598c69mo46po@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43b72c70$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,eeddadf8c21d2f02
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: Reading data from TServerSocket in TClientSocket
Date: Sat, 31 Dec 2005 19:45:42 -0800
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <thjer1h3bk668mqjsldbil598c69mo46po@4ax.com>
References: <43b72c70$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.69.81.148
X-Trace: newsgroups.borland.com 1136087020 69.69.81.148 (31 Dec 2005 19:43:40 -0700)
Lines: 46
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail