🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Reading data from TServerSocket in TClientSocket

#2877
From: Remy Lebeau (TeamB)
Date: Mon, 02 Jan 2006 22:49
53 lines
3306 bytes
"Maurice Anderson" <mauriceanderson@hotmail.com> wrote in message 
news:43b72c70$1@newsgroups.borland.com...

> However, when trying to read data from TScoket to
> the ClientSocket, it does not work.

Just saying that it does not work says nothing at all about the actual 
problem you are having.  Always provide specific details.

> Here is the code I put in the ClientSocket->OnRead event:

I assume, then, that you are using the TClientSocket in non-blocking mode? 
The code I gave you earlier was designed to be used in blocking mode, since 
you said that you were using TWinSocketStream.  The code has to be modified 
a bit to be usable with a non-blocking socket due to the more frequent 
occurances of incomplete data arriving in the socket at any given time.  The 
code you have so far is not enough to handle incoming packets in a reliable 
manner.  You must buffer all incoming data and then process it only when 
enough data is actually available.  You can go to http://www.deja.com and 
search the newsgroup archives.  Sample code has been posted many many times 
before.

> Here is the relevant code from the server end:

You are not doing any error cheecking in that code.  And I do not see you 
filling the TMemoryStream with any data before sending it.

> Is ClientSocket->OnRead executed in a seperate thread?

The OnRead event is triggered in the same thread that owns the 
TClientSocket.  TClientSocket is not a threaded component lik TServerSocket 
can be.  If you want to use TClientSocket with threads, then you have to 
manage the threading yourself.

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

That will only work if you use the TClientSocket in blocking mode. 
TClientSocket is not thread-safe in non-blocking mode.

> These Misc Read/Write functions are defined in both the server and the
> client.  I use the same functions for consistencies sake:

The functions will work as long as the data is accurate, which is not always 
the case with the code you have shown so far.

Also, I will mention that your use of ShowMessage() is not thread-safe.  You 
cannot safely use ShowMessage() outside of the main thread.  If you want to 
display a message in a thread-safe manner, then use the Win32 API 
MessageBox() function.


Gambit 
Technical Details
Message-ID: <43b9ad65$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!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: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <43b72c70$1@newsgroups.borland.com>
Subject: Re: Reading data from TServerSocket in TClientSocket
Date: Mon, 2 Jan 2006 14:49:00 -0800
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 68.69.17.41
Message-ID: <43b9ad65$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1136242021 68.69.17.41 (2 Jan 2006 14:47:01 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail