Article View: borland.public.cppbuilder.internet.socket
Article #585Re: Using TIdTCPServer
From: Peter
Date: Tue, 29 Jan 2008 17:29
Date: Tue, 29 Jan 2008 17:29
98 lines
4563 bytes
4563 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Peter" <piotrtrzeciak@yahoo.com> wrote in message
>news:479f51f8$1@newsgroups.borland.com...
>
>> It appears that my code "crashes" when more then one connection is
>> being established from the client and the IOHandler's InputBuffer gets
>> stepped on.
>
>Then you are using it wrong. Please show your actual code.
>
>> Is this buffer a separate one for each thread?
>
>For each connection, yes.
>
>
>Gambit
>
>
Here is the code:
void __fastcall Tlens_srvc::iln_rcv_socketExecute(TIdContext *AContext)
{
ImageData *imageData;
imageData = (ImageData *)malloc(sizeof(ImageData));
imageData->INITC = RawToBytes("\x00\xA1", 2);
imageData->DISPLAY = RawToBytes("\x00\xA9", 2);
imageData->EVN_MESSAGE = RawToBytes("\x00\xA7", 2);
AContext->Connection->IOHandler->ReadBytes(imageData->rcv_buffer, 20, false);
imageData->requested_length = 2;
imageData->msg = AContext->Connection->IOHandler->ReadSmallInt(true);
if (imageData->msg > 0) {
imageData->length = imageData->msg;
}
else {
// error
free(imageData);
return;
}
imageData->requested_length = imageData->length - 2;
AContext->Connection->IOHandler->ReadBytes(imageData->rcv_buffer, imageData->requested_length, false);
// This return is here only for testing to exit without reading more data.
//return;
//
// Figure out what command we are receiving
//
if ( (imageData->rcv_buffer[0] == imageData->INITC[0]) && (imageData->rcv_buffer[1] == imageData->INITC[1]) && (imageData->length > 4) ) {
// INITC as OINT, no reads, just write a response to the socket
processOint(AContext, imageData);
}
else {
if ( (imageData->rcv_buffer[0] == imageData->INITC[0]) && (imageData->rcv_buffer[1] == imageData->INITC[1]) && (imageData->length <=4) ) {
// INITC as INIT, no reads, just write a response to the socket
processInit(AContext, imageData);
}
else {
if ( (imageData->rcv_buffer[0] == imageData->DISPLAY[0]) && (imageData->rcv_buffer[1] == imageData->DISPLAY[1]) ) {
// DISPLAY... this is when we get an image and read more data from the socket
imageData->received_length = imageData->length;
receiveImage(AContext, imageData);
}
else {
if ( (imageData->rcv_buffer[0] == imageData->EVN_MESSAGE[0]) && (imageData->rcv_buffer[1] == imageData->EVN_MESSAGE[1]) ) {
// EVN_MESSAGE. Error messages will come down from the host here, no more data from socket, just interpret message
getEvnMessage(AContext, imageData);
}
else {
// Other command... no processing
}
}
}
}
//
// Clean up
//
free(imageData);
}
Now, I put in a return statement in the middle, just to see if I can get more than one connection, but it still fails.
For any "command" other than DISPLAY, it works fine, because they only come as single connections. If I get a series of DISPLAY commands, the first one usually goes ok (depends on the timing), but the second client connection kills the service.
The only other thing I can think of, is that I'm adding the TIdTCPServer component to a wrong place (TService), and that's why it gets "clobbered".
I have to admit, it took me less to write this whole app from scratch the first time around, than to get Indy working :-( (but I think it's just a lack of docs and experience).
Thanks again.
Technical Details
Message-ID:
<479f7070$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<478e1c34$1@newsgroups.borland.com> <478e4760@newsgroups.borland.com> <4798a5e1$1@newsgroups.borland.com> <4798cf30$1@newsgroups.borland.com> <4798db8f$1@newsgroups.borland.com> <4798ef34$2@newsgroups.borland.com> <479e2c75$1@newsgroups.borland.com> <479e382e$1@newsgroups.borland.com> <479f4835$1@newsgroups.borland.com> <479f51f8$1@newsgroups.borland.com> <479f68b1$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,452e664b18b0b56c X-Google-Attributes: gid11508e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Peter" <piotrtrzeciak@yahoo.com> Sender: "Peter" <piotrtrzeciak@yahoo.com> Reply-To: "Peter" <piotrtrzeciak@yahoo.com> Subject: Re: Using TIdTCPServer Newsgroups: borland.public.cppbuilder.internet.socket X-User-Info: 207.45.45.41 References: <478e1c34$1@newsgroups.borland.com> <478e4760@newsgroups.borland.com> <4798a5e1$1@newsgroups.borland.com> <4798cf30$1@newsgroups.borland.com> <4798db8f$1@newsgroups.borland.com> <4798ef34$2@newsgroups.borland.com> <479e2c75$1@newsgroups.borland.com> <479e382e$1@newsgroups.borland.com> <479f4835$1@newsgroups.borland.com> <479f51f8$1@newsgroups.borland.com> <479f68b1$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <479f7070$1@newsgroups.borland.com> Date: 29 Jan 2008 10:29:04 -0700 X-Trace: newsgroups.borland.com 1201631344 207.105.83.66 (29 Jan 2008 10:29:04 -0700) Lines: 100 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail