🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Blocking Client

#4535
From: Remy Lebeau (TeamB)
Date: Thu, 20 Jan 2005 22:54
37 lines
2594 bytes
"mike" <mfbrowne@earthlink.net> wrote in message
news:41f01cbc@newsgroups.borland.com...

> Ok I understand what you have indicated, but now I am confused as
> to how I would implement the reading of the data. Would I simply use
> a timer in which my WinSocketStream Wait ForData() is located.

You missed the point I was trying to make earlier.  You only need to use a
thread/timer when you want to do other things while waiting for data to
arrive.  If you are sending data and then expecting a response to come back
immediately, you don't need to use a thread or timer at all.  Just read
immediately after writing, ie:

    TWinSocketStream *Stream = new TWinSocketStream(ClientSocket1->Socket,
5000);
    Stream->Write(SomeData, DataSize);
    while( !Stream->WaitForData(1000) ) Sleep(50);
    Stream->Read(SomeBuffer, SomeSize);
    //...

> If I understand correctly the WaitForData() would stall all other
> operations until such time as data actually was received or it timed
> out.

Only if you are using the socket in the same thread as the other operations.

> The application itself is required to send and receive data based upon
> the user making choices through button clicks and so forth. In this type
> of situation would I be better to use a thread as I don't know when or
> whaic type of data will be received from the server.

If you do not know when data will arrive, and/or the received data is
arriving unsolicited, then yes, use a thread for the reading.


Gambit
Technical Details
Message-ID: <41f03619$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!news2.euro.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
References: <41f00ec6$1@newsgroups.borland.com> <41f015df$1@newsgroups.borland.com> <41f01cbc@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,8975bc0a9ed70a81
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: <41f00ec6$1@newsgroups.borland.com> <41f015df$1@newsgroups.borland.com> <41f01cbc@newsgroups.borland.com>
Subject: Re: Blocking Client
Date: Thu, 20 Jan 2005 14:54:33 -0800
Lines: 39
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: <41f03619$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1106261529 68.69.17.41 (20 Jan 2005 14:52:09 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!news2.euro.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