Mega Search
23.2 Million


Sign Up

Make a donation  
Problem sending an structure with TIdTCPClient  
News Group: borland.public.cppbuilder.internet.socket

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

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 12-Dec-2007, at 9:12 PM EST
From: Star
 
Re: Problem sending an structure with TIdTCPClient  
News Group: borland.public.cppbuilder.internet.socket
"Star"  wrote in message 
news:47612bf3@newsgroups.borland.com...

> Yes, I know I cannot use AnsiString. My structure looks like this:

> I just checked the Indy version and is 10.1.5

In that case:

    CLIENTTOSERVERCMD mycmd;
    ...
    IdTCPClient->IOHandler->Write(RawToBytes(&mycmd, sizeof(mycmd)));


Gambit 



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 13-Dec-2007, at 9:31 AM EST
From: Remy Lebeau \(TeamB\)
 
Re: Problem sending an structure with TIdTCPClient  
News Group: borland.public.cppbuilder.internet.socket
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"  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 
> 
> 

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 13-Dec-2007, at 1:56 PM EST
From: Star
 
Re: Problem sending an structure with TIdTCPClient  
News Group: borland.public.cppbuilder.internet.socket
"Star"  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 



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Dec-2007, at 1:57 PM EST
From: Remy Lebeau \(TeamB\)
 
Re: Problem sending an structure with TIdTCPClient  
News Group: borland.public.cppbuilder.internet.socket
I'm using C++ Builder 2007. Not sure what version of Indy comes with that.



Remy Lebeau (TeamB) wrote:
> "Star"  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 
> 
> 

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Dec-2007, at 9:32 PM EST
From: Star
 
Re: Problem sending an structure with TIdTCPClient  
News Group: borland.public.cppbuilder.internet.socket
"Star"  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 



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Dec-2007, at 12:22 PM EST
From: Remy Lebeau \(TeamB\)