Thread View: borland.public.cppbuilder.internet.socket
8 messages
8 total messages
Started by Patryk B.
Wed, 12 Sep 2007 09:19
ServerSocket and Threads
Author: Patryk B.
Date: Wed, 12 Sep 2007 09:19
Date: Wed, 12 Sep 2007 09:19
21 lines
1426 bytes
1426 bytes
Hello, Im using ServerSocket and Threads (http://dn.codegear.com/article/26276). I have problem with closing server application when some clients are connected. On FormClose event i have code: ServerSocet->Active=false; And everythink is ok when any client isn't connected. When client is connected and im trying to close application it hang. I think that i should disconnect client/terminate active threads befor close application? Best regards, Patryk B.
Re: ServerSocket and Threads
Author: Brendan Melia
Date: Wed, 12 Sep 2007 10:57
Date: Wed, 12 Sep 2007 10:57
29 lines
1639 bytes
1639 bytes
Patryk B. wrote: > Hello, > > Im using ServerSocket and Threads (http://dn.codegear.com/article/26276). > > I have problem with closing server application when some clients are > connected. > On FormClose event i have code: > > ServerSocet->Active=false; > > And everythink is ok when any client isn't connected. > When client is connected and im trying to close application it hang. > I think that i should disconnect client/terminate active threads befor > close application? > > Best regards, > > Patryk B. You need to close the server. This then ensures the relevant TCP/IP state packets are sent to any attached clients. ServerSocket->Close(); Bren.
Re: ServerSocket and Threads
Author: Patryk B.
Date: Wed, 12 Sep 2007 11:34
Date: Wed, 12 Sep 2007 11:34
15 lines
1359 bytes
1359 bytes
> You need to close the server. This then ensures the relevant TCP/IP
> state packets are sent to any attached clients.
>
> ServerSocket->Close();
>
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
ServerSocket->Close();
}
It dosent work, still when some client is connected it hang out,
I need to close client, then server is closing properly.
Patryk.
Re: ServerSocket and Threads
Author: Remy Lebeau (TeamB)
Date: Wed, 12 Sep 2007 17:14
Date: Wed, 12 Sep 2007 17:14
11 lines
1170 bytes
1170 bytes
"Brendan Melia" <bmelia@hiden.co.uk> wrote in message news:46e7c63b@newsgroups.borland.com... > You need to close the server. He already is. All Close() does is sets the Active property to false, which he's doing directly. Gambit
Re: ServerSocket and Threads
Author: Remy Lebeau (TeamB)
Date: Wed, 12 Sep 2007 17:14
Date: Wed, 12 Sep 2007 17:14
12 lines
1282 bytes
1282 bytes
"Patryk B." <pbobak@no.spam.o2.pl> wrote in message news:op.tyjavhtkwzezly@dune.intranet... > I have problem with closing server application when > some clients are connected. Please show the actual code that you are using. Your thread code is likely not responding to disconnects properly. Gambit
Re: ServerSocket and Threads
Author: Patryk B.
Date: Thu, 13 Sep 2007 07:30
Date: Thu, 13 Sep 2007 07:30
28 lines
1678 bytes
1678 bytes
Dnia 12-09-2007 o 19:14:54 Remy Lebeau (TeamB) <no.spam@no.spam.com> napisa�(a): > Please show the actual code that you are using. Your thread code is > likely > not responding to disconnects properly. For test im using code from http://dn.codegear.com/article/26276 As client im using telnet. It hang beacuse i delete: if (pStream->WaitForData(CLIENTWAITTIME)) I want disconnect client only when server is going to shutdown. In all I can set time for few hours and for my future use it will be ok but im interesting how to do that. > Gambit > > Patryk. -- U�ywam klienta poczty Opera Mail: http://www.opera.com/mail/
Re: ServerSocket and Threads
Author: Remy Lebeau (TeamB)
Date: Thu, 13 Sep 2007 07:55
Date: Thu, 13 Sep 2007 07:55
61 lines
2695 bytes
2695 bytes
"Patryk B." <pbobak@no.spam.o2.pl> wrote in message
news:op.tyk0galowzezly@dune.intranet...
> It hang beacuse i delete:
>
> if (pStream->WaitForData(CLIENTWAITTIME))
You need that line in order to detect a graceful disconnect from the client.
When WaitForData() returns true, and then Read() returns 0, the connection
has been disconnected by the client.
> I want disconnect client only when server is going to shutdown.
Then simply remove the call to Close() when WaitForData() returns false, ie:
void __fastcall TMyServerThread::ClientExecute(void)
{
char buffer[BUFFERSIZE];
int iRead;
try
{
TWinSocketStream *pStream = new TWinSocketStream(ClientSocket,
CLIENTWAITTIME);
try
{
while( (!Terminated) && (ClientSocket->Connected) )
{
if( !pStream->WaitForData(CLIENTWAITTIME) )
continue;
iRead = pStream->Read(buffer, sizeof(buffer);
if( iRead < 1 )
{
if( iRead == 0 )
// client disconnected...
else
// socket error...
ClientSocket->Close();
}
else
{
// process buffer up to iRead bytes...
}
}
}
__finally
{
delete pStream;
}
}
catch (...)
{
// handle exception...
}
}
Gambit
Re: ServerSocket and Threads
Author: Patryk B.
Date: Thu, 13 Sep 2007 08:34
Date: Thu, 13 Sep 2007 08:34
7 lines
1273 bytes
1273 bytes
Dnia 13-09-2007 o 09:55:44 Remy Lebeau (TeamB) <no.spam@no.spam.com> napisa�(a): Work perfectly. Thanks for help and quick answer :) Patryk.
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