Thread View: borland.public.cppbuilder.internet.socket
1 messages
1 total messages
Started by Volodymyr Novikov
Sun, 07 Aug 2005 23:04
Is PowerSocket blocking by default?
Author: Volodymyr Novikov
Date: Sun, 07 Aug 2005 23:04
Date: Sun, 07 Aug 2005 23:04
73 lines
2926 bytes
2926 bytes
Hi,
I am writing a small application using TPowesock.
It appeared that event OnRead called over and over again even though all
incoming data is read. In the following code ReadLineEvent(TObject *Sender)
procedure always executed without incoming data.
Any suggestions?
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (Psock1->Connected)
{Button1->Caption="Connect";
Psock1->Disconnect();
Psock1->Tag=0;}
else Psock1->Connect();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Psock1Connect(TObject *Sender)
{
Button1->Caption="Disconnect";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Psock1->OnRead=ReadEvent;
}
//---------------------------------------------------------------------------
// This is the procedure that will be assigned to the OnRead event
void __fastcall TForm1::ReadEvent(TObject *Sender)
{
ch=Psock1->Read(1);
lastline=lastline+ch;
Bar1->Panels->Items[0]->Text=Bar1->Panels->Items[0]->Text+ch;
if (lastline=="login:")
{Psock1->Writeln(login);
Bar1->Panels->Items[1]->Text=login;
lastline="";
Bar1->Panels->Items[0]->Text="";}
if (lastline=="password:")
{Psock1->Writeln(password);
Bar1->Panels->Items[1]->Text=password;
lastline="";
Bar1->Panels->Items[0]->Text="";}
if (lastline==welcome)
{lastline="";
ch=Psock1->Read(2);
Psock1->TimeOut=50;
Psock1->OnRead=ReadLineEvent;}
}
//---------------------------------------------------------------------------
// This is the procedure that will be assigned to the OnRead event after
login was succsessful
void __fastcall TForm1::ReadLineEvent(TObject *Sender)
{
try
{
ch=Psock1->Read(1);
}
catch(...)
{
lastline=ch;
Bar1->Panels->Items[0]->Text=ch;
}
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads