Article View: borland.public.cppbuilder.internet.socket
Article #5327What is actually happening with this simple (TCS/TSS) example?
From: Vladimir Stefanovic
Date: Wed, 18 Aug 2004 07:19
Date: Wed, 18 Aug 2004 07:19
79 lines
3026 bytes
3026 bytes
Hi,
I have some misunderstanding of behavior of simple sending
strings from TClientSocket to TServerSocket in some cases.
The server's code is the same in all cases. Server is supposed
to read text and display it in Memo1. ServerSocket1 is set to
'Active = true' and 'ServerType = stNonBlocking' at design-time.
Port is also set to 1101 at both sides at design-time. All examples
are tested on a single PC.
// Server reading/displaying code ...
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
Memo1->Lines->Add( Socket->ReceiveText() );
}
// Client sending code...
CASE 1: ( Works )
Design-Time:
Active=true;
ClientType=ctNonBlocking;
Address=128.128.129.162;
void __fastcall TForm1::SendButtonClick(TObject *Sender)
{
ClientSocket1->Socket->SendText( "Test!" );
}
CASE 2: ( Does NOT work when ctNonBlocking )
Design-Time:
Active=false;
ClientType=ctNonBlocking; // <-- works when ctBlocking
Address=[Empty];
void __fastcall TForm1::SendButtonClick(TObject *Sender)
{
if ( ClientSocket1->Active == true )
ClientSocket1->Close();
ClientSocket1->Address="128.128.129.162";
ClientSocket1->Open();
ClientSocket1->Socket->SendText( "Test!" );
}
CASE 3: (Works on second and all other SendButton clicks, but
fails on first click ?! Also tried with...
if ( Socket->ReceiveLength() < 1 )
return;
... but no changes. When tested on LAN (not on a single PC) does
not work at all.
Design-Time:
Active=false;
ClientType=ctNonBlocking;
Address=[Empty];
void __fastcall TForm1::SendButtonClick(TObject *Sender)
{
if ( ClientSocket1->Active == true )
ClientSocket1->Close();
ClientSocket1->Address="128.128.129.162";
ClientSocket1->Open();
Application->ProcessMessages(); // <-- This line was added
ClientSocket1->Socket->SendText( "Test!" );
}
Why all this works in Blocking mode and not in NonBlocking?
Best regards,
Vladimir Stefanovic
Technical Details
Message-ID:
<41230302$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,2324423512352dca,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Vladimir Stefanovic" <antivari@ptt.yu> Sender: "Vladimir Stefanovic" <antivari@ptt.yu> Reply-To: "Vladimir Stefanovic" <antivari@ptt.yu> Subject: What is actually happening with this simple (TCS/TSS) example? Newsgroups: borland.public.cppbuilder.internet.socket X-User-Info: 213.137.116.130 X-Forwarded-For: 128.128.129.165 NNTP-Posting-Host: 207.105.83.66 Message-ID: <41230302$1@newsgroups.borland.com> Date: 18 Aug 2004 00:19:30 -0700 X-Trace: newsgroups.borland.com 1092813570 207.105.83.66 (18 Aug 2004 00:19:30 -0700) Lines: 80 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail