2 ways of writing TIdBytes to a StringStream generate different results

Giganews Newsgroups
Subject: 2 ways of writing TIdBytes to a StringStream generate different results
Posted by:  koen (ko…@ha.com)
Date: Wed, 28 Mar 2007

Hello,

I have a small application in wich I send a TIdMessage using UDP like
this:

TStringStream *Stream = new TStringStream ("");

try
{
  IdMessage->SaveToStream (Stream);

  UDPClient->Send (Stream->DataString);
}
__finally
{
  delete Stream;
}

To decode the message on the serverside, in the OnUDPRead-event, I tried
2 ways to read the message, but only the first one seems to work (In both
cases AData is the TIdBytes-argument of the OnUDPRead-event):

method1:
---------

TStream *Stream = new TStringStream (BytesToString (AData));

try
{
  IdMessage->LoadFromStream (Stream);
}
__finally
{
  delete Stream;
}

method2:
---------

TStream *Stream = new TStringStream ("");

try
{
  WriteTIdBytesToStream (Stream, AData);
  IdMessage->LoadFromStream (Stream);
}
__finally
{
  delete Stream;
}

Is this intended behaviour, and should I handle the second method
differently, or should this normally work both?

regards,

Koen

Replies