Thread View: borland.public.cppbuilder.internet.socket
5 messages
5 total messages
Started by OKusmen
Tue, 03 Aug 2004 08:20
Client Socket Connect Question
Author: OKusmen
Date: Tue, 03 Aug 2004 08:20
Date: Tue, 03 Aug 2004 08:20
10 lines
1538 bytes
1538 bytes
I use TClientSocket. I want to get help about this component working. I want to send messages. First message is for a host that is not available in the network now. After my connection request, connection error event occurs(eeLookup errorcode). This is normal situation that I expect. After this event, I want to send another message to another client that is available in the network. I expect that connection event occurs, but does not. Again, error event occurs with eeConnect error code. I try this message to same host again. This time, connection is established. In this scenario, I have to try a message two times. But, I want to try once. What reason occurs this situation.
Re: Client Socket Connect Question
Author: Remy Lebeau (TeamB)
Date: Tue, 03 Aug 2004 16:33
Date: Tue, 03 Aug 2004 16:33
11 lines
1153 bytes
1153 bytes
"OKusmen" <okusmen@aselsan.com.tr> wrote in message news:410f4afe@newsgroups.borland.com... > In this scenario, I have to try a message two times. But, > I want to try once. What reason occurs this situation. Please show your actual code. Gambit
Re: Client Socket Connect Question
Author: OKusmen
Date: Wed, 04 Aug 2004 08:21
Date: Wed, 04 Aug 2004 08:21
62 lines
2720 bytes
2720 bytes
void TTCPSendDataModule::OpenConnection()
{
SendSocket->Host = TCPSendTable->FieldValues["HostName"];
SendSocket->Port = TCPSendTable->FieldValues["PortNo"];
try{
SendSocket->Open();
connectionWaiting = true;
}catch(...){}
}
//--------------------------------------------------------------------------
-
void __fastcall TTCPSendDataModule::SendSocketRead(TObject *Sender,
TCustomWinSocket *Socket)
{
ReadIncomingPacket();
}
//--------------------------------------------------------------------------
-
void __fastcall TTCPSendDataModule::SendSocketConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
SendPacketInOrder();
connectionWaiting = false;
}
//--------------------------------------------------------------------------
-
void __fastcall TTCPSendDataModule::SendSocketError(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
CloseSendSocket();
ErrorCode = 0;
connectionWaiting = false;
}
//--------------------------------------------------------------------------
-
bool TTCPSendDataModule::SendPacket(BYTE *buffer,int bufferLength)
{
bool result = false;
try
{
if( SendSocket->Active &&
SendSocket->Socket->SendBuf(buffer,bufferLength) == bufferLength ) // packet
is sent sucessfully
result = true;
}catch(...){}
return result;
}
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:410fbe48$1@newsgroups.borland.com...
>
> "OKusmen" <okusmen@aselsan.com.tr> wrote in message
> news:410f4afe@newsgroups.borland.com...
>
> > In this scenario, I have to try a message two times. But,
> > I want to try once. What reason occurs this situation.
>
> Please show your actual code.
>
>
> Gambit
>
>
Re: Client Socket Connect Question
Author: Remy Lebeau (TeamB)
Date: Wed, 04 Aug 2004 17:30
Date: Wed, 04 Aug 2004 17:30
78 lines
3226 bytes
3226 bytes
"OKusmen" <okusmen@aselsan.com.tr> wrote in message
news:41109cf1@newsgroups.borland.com...
> void TTCPSendDataModule::OpenConnection()
> {
> SendSocket->Host = TCPSendTable->FieldValues["HostName"];
> SendSocket->Port = TCPSendTable->FieldValues["PortNo"];
Where exactly are you getting the Host and Port values from? What are the
actual values themselves?
> try{
> SendSocket->Open();
> connectionWaiting = true;
> }catch(...){}
You should always catch VCL exceptions explitically, don't use '...':
catch(const Exception &){}
> if( SendSocket->Active &&
> SendSocket->Socket->SendBuf(buffer,bufferLength) == bufferLength ) //
packet
> is sent sucessfully
> result = true;
> }catch(...){}
FYI, just because SendBuf() may not take the full data at one time is not an
error. Only when it returns -1 or throws an exception is it an error. You
should be looping through the data until you have sent it all, ie:
bool TTCPSendDataModule::SendPacket(BYTE *buffer,int bufferLength)
{
if( SendSocket->Active )
{
try
{
while( bufferlength > 0 )
{
int sent = SendSocket->Socket->SendBuf(buffer,
bufferLength);
if( sent < 0 )
{
if( SendSocket->Active )
{
// send would block, try again...
Application->ProcessMessages();
continue;
}
// error sending and OnError already caught it...
return false;
}
if( sent == 0 )
{
// disconnected...
return false;
}
buffer += sent;
bufferlength -= sent;
}
// finished...
return true;
}
catch(const Exception &)
{
// error...
}
}
return false;
}
Gambit
Re: Client Socket Connect Question
Author: OKusmen
Date: Thu, 05 Aug 2004 07:17
Date: Thu, 05 Aug 2004 07:17
88 lines
3646 bytes
3646 bytes
I take host and port values from db-table. Firstly, Read them from table
and set them into socket's parameters. Actual values:
Host = "bosterminal"
Port = 50102
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:41111ce5$1@newsgroups.borland.com...
>
> "OKusmen" <okusmen@aselsan.com.tr> wrote in message
> news:41109cf1@newsgroups.borland.com...
>
> > void TTCPSendDataModule::OpenConnection()
> > {
> > SendSocket->Host = TCPSendTable->FieldValues["HostName"];
> > SendSocket->Port = TCPSendTable->FieldValues["PortNo"];
>
> Where exactly are you getting the Host and Port values from? What are the
> actual values themselves?
>
> > try{
> > SendSocket->Open();
> > connectionWaiting = true;
> > }catch(...){}
>
> You should always catch VCL exceptions explitically, don't use '...':
>
> catch(const Exception &){}
>
> > if( SendSocket->Active &&
> > SendSocket->Socket->SendBuf(buffer,bufferLength) == bufferLength ) //
> packet
> > is sent sucessfully
> > result = true;
> > }catch(...){}
>
> FYI, just because SendBuf() may not take the full data at one time is not
an
> error. Only when it returns -1 or throws an exception is it an error.
You
> should be looping through the data until you have sent it all, ie:
>
> bool TTCPSendDataModule::SendPacket(BYTE *buffer,int bufferLength)
> {
> if( SendSocket->Active )
> {
> try
> {
> while( bufferlength > 0 )
> {
> int sent = SendSocket->Socket->SendBuf(buffer,
> bufferLength);
> if( sent < 0 )
> {
> if( SendSocket->Active )
> {
> // send would block, try again...
> Application->ProcessMessages();
> continue;
> }
>
> // error sending and OnError already caught it...
> return false;
> }
>
> if( sent == 0 )
> {
> // disconnected...
> return false;
> }
>
> buffer += sent;
> bufferlength -= sent;
> }
>
> // finished...
> return true;
> }
> catch(const Exception &)
> {
> // error...
> }
> }
> return false;
> }
>
>
> Gambit
>
>
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