Article View: borland.public.cppbuilder.internet.socket
Article #2973Re: Reading data from TServerSocket in TClientSocket
From: Maurice Anderson
Date: Sun, 01 Jan 2006 04:06
Date: Sun, 01 Jan 2006 04:06
44 lines
2217 bytes
2217 bytes
>I think you are supposed to Synchronize() with the main thread first.
Hello Bob, I updated my code with your suggestions but to no avail..... as
in:
while (!Terminated && ClientSocket->Connected)
{
if (pStream->WaitForData(6000))
{
ReadPacket(pStream);
Synchronize(DoStuffOnMainForm);
}
}
void __fastcall TMyServerThread::DoStuffOnMainForm(void)
{
AnsiString FileName = "Hello World";
Strm2 = new TMemoryStream;
Strm2->Clear();
BinaryTransfer1->SendTextMessage(Strm2, FileName);
ClientSocket->SendBuf(Strm2->Memory, Strm2->Size);
}
> Should be larger than BytesToReceive.
> char * Buffer = new char[BytesToReceive];
I also replaced char *Buffer[256] with char * Buffer = new
char[BytesToReceive];
> >(2) Is ClientSocket->OnRead executed in a seperate thread?
>
> Yes, usually.
Are you saying that there are times that ClientSocket->OnRead will execute
in the main thread? If so what would cause it to alternate between
executing in a seperate thread and executing in the main thread?
> > (4) And if so, how do I accomplish that?
>
> Use the OnRead event.
That's the event my code is executing in
Technical Details
Message-ID:
<43b753c8$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<43b72c70$1@newsgroups.borland.com> <thjer1h3bk668mqjsldbil598c69mo46po@4ax.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: "Maurice Anderson" <mauriceanderson@hotmail.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <43b72c70$1@newsgroups.borland.com> <thjer1h3bk668mqjsldbil598c69mo46po@4ax.com> Subject: Re: Reading data from TServerSocket in TClientSocket Date: Sat, 31 Dec 2005 20:06:45 -0800 Lines: 47 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 64.30.203.223 Message-ID: <43b753c8$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1136088008 64.30.203.223 (31 Dec 2005 20:00:08 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail