Article View: borland.public.cppbuilder.internet.socket
Article #4545Re: Blocking Client
From: mike
Date: Fri, 21 Jan 2005 14:35
Date: Fri, 21 Jan 2005 14:35
58 lines
3089 bytes
3089 bytes
Remy, Hopefully I am getting closer to getting this to function properly. Remy should I use the synconize() method to process any data messages coming into the threaded socket. The processing of the messages will require updates to controls and data on forms in the main thread. The other thing is, are there any other issues I need to watch for when using the threaded approach to reading the socket data. Thanks Mike "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:41f03619$1@newsgroups.borland.com... > > "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:
<41f11362$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41f00ec6$1@newsgroups.borland.com> <41f015df$1@newsgroups.borland.com> <41f01cbc@newsgroups.borland.com> <41f03619$1@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: "mike" <mfbrowne@earthlink.net> Newsgroups: borland.public.cppbuilder.internet.socket References: <41f00ec6$1@newsgroups.borland.com> <41f015df$1@newsgroups.borland.com> <41f01cbc@newsgroups.borland.com> <41f03619$1@newsgroups.borland.com> Subject: Re: Blocking Client Date: Fri, 21 Jan 2005 09:35:54 -0500 Lines: 60 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 68.204.189.169 Message-ID: <41f11362$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1106318178 68.204.189.169 (21 Jan 2005 06:36:18 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail