Hallo mal wieder hab mal wieder zeit mich mit meinen Projekten zubefassen und mir ist da ein problem untergekommen wo ich grad drann hänge:
Ich erstelle einen MemoryStream speichere Daten rein und verschicke diesen über
indy 10 socket alles kein problem nur beim lesen fehlen bei dem im Stream gespeichertem String die Hälfte der Buchstaben. Kann mir einer sagen wo ich mist gebaut habe?
Stream Erzeugen:
Delphi-Quellcode:
procedure TIsoClientClass.Send;
var hStream :TStream;
hSize : Integer;
begin
hStream := TMemoryStream.Create;
try
hStream.Write(aCMD,Sizeof(aCmd));
hSize := length(aMsg);
hStream.Write(hSize, Sizeof(hSize));
hStream.Write(PChar(aMsg)^,hSize);
hStream.Position := 0;
hSize := (HStream.Size);
fSocket.Socket.WriteStream(hStream,hSize);
finally
hStream.free;
end;
end;
Stream Senden
Delphi-Quellcode:
procedure TSocketHelper.WriteStream(aStream: TStream;var Size: Integer);
begin
if Assigned(fContext) then
Begin
try
fContext.Connection.IOHandler.Write(LongInt(Size));
fContext.Connection.IOHandler.WriteBufferOpen;
fContext.Connection.IOHandler.Write(aStream,Size);
fContext.Connection.IOHandler.WriteBufferFlush;
finally
fContext.Connection.IOHandler.WriteBufferClose;
end;
End;
if Assigned(fClient) then
Begin
try
fClient.IOHandler.Write(LongInt(Size));
fClient.IOHandler.WriteBufferOpen;
fClient.IOHandler.Write(aStream,Size);
fClient.IOHandler.WriteBufferFlush;
finally
fClient.IOHandler.WriteBufferClose;
end;
End;
end;
Stream empfangen :
Delphi-Quellcode:
procedure TSocketHelper.ReadStream(aStream: TStream;var Size: Integer);
begin
if Assigned(fContext) then
Begin
Size := fContext.Connection.IOHandler.ReadLongInt;
fContext.Connection.IOHandler.ReadStream(aStream,Size);
End;
if Assigned(fClient) then
Begin
Size := fClient.IOHandler.ReadLongInt;
fClient.IOHandler.ReadStream(aStream,Size);
End;
end;
Stream auslesen:
Delphi-Quellcode:
procedure TIsoServerClass.Execute(aClient: TSocketHelper);
var hStream : TStream;
hSize : Integer;
hMsg :String;
hCmd : Word;
begin
hStream := TMemoryStream.Create;
try
aClient.ReadStream(hStream,hSize);
hStream.Position := 0;
hStream.Read(hCmd,SizeOf(hCmd));
hStream.Read(hSize,Sizeof(hSize));
SetLength(hMsg,hSize);
hStream.Read(pChar(hMsg)^,hSize);
finally
hStream.Free;
end;
end;