Thread View: borland.public.cppbuilder.internet.socket
6 messages
6 total messages
Started by Star
Wed, 12 Dec 2007 20:12
Problem sending an structure with TIdTCPClient
Author: Star
Date: Wed, 12 Dec 2007 20:12
Date: Wed, 12 Dec 2007 20:12
17 lines
1300 bytes
1300 bytes
I'm sorry... but I posted this message in the wrong forum by mistake. This one is the right one. Hi, I'm not sure how to do this. I used to do that with TClientSocket, but I cannot find the way of doing the same thing with TIdTCPClient. Something like this... CLIENTTOSERVERCMD mycmd; ... IdTCPClient->Socket->Write((char *)&mycmd, sizeof(mycmd),true); Any ideas? Thanks
Re: Problem sending an structure with TIdTCPClient
Author: Remy Lebeau (TeamB)
Date: Wed, 12 Dec 2007 20:22
Date: Wed, 12 Dec 2007 20:22
24 lines
1926 bytes
1926 bytes
"Star" <noemail@noemail.com> wrote in message news:4760409e$1@newsgroups.borland.com... > I'm not sure how to do this. I used to do that with TClientSocket, > but I cannot find the way of doing the same thing with TIdTCPClient. What version of Indy are you actually using? It makes a difference in how the code has to look. > CLIENTTOSERVERCMD mycmd; What type of members does CLIENTTOSERVERCMD actually contain? > IdTCPClient->Socket->Write((char *)&mycmd, sizeof(mycmd),true); Do not use the Socket property directly like that. TIdTCPConnection (which TIdTCPClient derives from) in Indy 9, and TIdIOHandler in Indy 10, have many reading/writing methods of their own that you need to use instead. For instance, in Indy 9, you could use TIdTCPConnection::WriteBuffer(), and in Indy 10 you could use RawToBytes() and TIdIOHandler.Write(TIdBytes) instead. Gambit
Re: Problem sending an structure with TIdTCPClient
Author: Star
Date: Wed, 12 Dec 2007 20:32
Date: Wed, 12 Dec 2007 20:32
31 lines
2127 bytes
2127 bytes
I'm using C++ Builder 2007. Not sure what version of Indy comes with that. Remy Lebeau (TeamB) wrote: > "Star" <noemail@noemail.com> wrote in message > news:4760409e$1@newsgroups.borland.com... > >> I'm not sure how to do this. I used to do that with TClientSocket, >> but I cannot find the way of doing the same thing with TIdTCPClient. > > What version of Indy are you actually using? It makes a difference in how > the code has to look. > >> CLIENTTOSERVERCMD mycmd; > > What type of members does CLIENTTOSERVERCMD actually contain? > >> IdTCPClient->Socket->Write((char *)&mycmd, sizeof(mycmd),true); > > Do not use the Socket property directly like that. TIdTCPConnection (which > TIdTCPClient derives from) in Indy 9, and TIdIOHandler in Indy 10, have many > reading/writing methods of their own that you need to use instead. For > instance, in Indy 9, you could use TIdTCPConnection::WriteBuffer(), and in > Indy 10 you could use RawToBytes() and TIdIOHandler.Write(TIdBytes) instead. > > > Gambit > >
Re: Problem sending an structure with TIdTCPClient
Author: Remy Lebeau (TeamB)
Date: Wed, 12 Dec 2007 21:57
Date: Wed, 12 Dec 2007 21:57
19 lines
1908 bytes
1908 bytes
"Star" <noemail@noemail.com> wrote in message news:4760457a$1@newsgroups.borland.com... > I'm using C++ Builder 2007. Not sure what version of Indy comes with that. Indy 9 (not sure which build) and Indy 10.1.5. So how you send your struct still depends on what version of Indy you configured when you installed the IDE. As I mentioned, your code will look different depending on which version you are actually using. Right-click on any Indy component in the form designer to find out. You didn't answer my other question - what does CLIENTTOSERVERCMD contain inside of it. I only ask because if you are using AnsiString or other dynamically-allocated fields, then you can't send your struct as-is at all, regardless of your Indy version. Gambit
Re: Problem sending an structure with TIdTCPClient
Author: Star
Date: Thu, 13 Dec 2007 12:56
Date: Thu, 13 Dec 2007 12:56
38 lines
2264 bytes
2264 bytes
Yes, I know I cannot use AnsiString. My structure looks like this:
typedef struct ClientToServerCommand
{
int nMessageType;
char cGUID[255];
char cUserData[255];
} CLIENTTOSERVERCMD;
I just checked the Indy version and is 10.1.5
Thanks for your help.
Remy Lebeau (TeamB) wrote:
> "Star" <noemail@noemail.com> wrote in message
> news:4760457a$1@newsgroups.borland.com...
>
>> I'm using C++ Builder 2007. Not sure what version of Indy comes with that.
>
> Indy 9 (not sure which build) and Indy 10.1.5. So how you send your struct
> still depends on what version of Indy you configured when you installed the
> IDE. As I mentioned, your code will look different depending on which
> version you are actually using. Right-click on any Indy component in the
> form designer to find out.
>
> You didn't answer my other question - what does CLIENTTOSERVERCMD contain
> inside of it. I only ask because if you are using AnsiString or other
> dynamically-allocated fields, then you can't send your struct as-is at all,
> regardless of your Indy version.
>
>
> Gambit
>
>
Re: Problem sending an structure with TIdTCPClient
Author: Remy Lebeau (TeamB)
Date: Thu, 13 Dec 2007 17:31
Date: Thu, 13 Dec 2007 17:31
16 lines
1431 bytes
1431 bytes
"Star" <noemail@noemail.com> wrote in message
news:47612bf3@newsgroups.borland.com...
> Yes, I know I cannot use AnsiString. My structure looks like this:
<snip>
> I just checked the Indy version and is 10.1.5
In that case:
CLIENTTOSERVERCMD mycmd;
...
IdTCPClient->IOHandler->Write(RawToBytes(&mycmd, sizeof(mycmd)));
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