Delphi 7 and Indy 9 writing data from TCPServer -
i have delphi program sits server receiving data , sending small acknowledgement packets. used code (edited brevity)
procedure tdmserver.onexecutetcpserver(athread: tidpeerthread); var incomingpacket : string; responsepacket : string; begin incomingpacket := athread.connection.readln(#$03); if incomingpacket <> '' begin responsepacket := processtelegram(incomingpacket); athread.connection.writeln(responsepacket); end; athread.connection.disconnect; end;
this works fine, apart appending end of line crlf sends, client (not under control) doesn't like.
so changed to:
athread.connection.write(responsepacket);
and nothing received on client.
then tried
athread.connection.writebuffer(responsepacket, length(responsepacket), true);
to try , write immediately, still doesn't send @ all.
i have put in delays, tried opening buffer, flushing , closing again (like file), still no joy , time flushwritebuffer called av.
i'm stuck. please offer words of wisdom?
readln()
strips off terminator result. processtelegram()
accounting that? if needs terminator, have add in manually, eg:
processtelegram(incomingpacket + #03)
is responsepacket
being formatted correctly client expecting? if client not expecting terminating crlf, using write()
instead of writeln()
correct thing do.
if use writebuffer()
, must dereference string in order pass correct data address writebuffer()
, eg:
writebuffer(responsepacket[1], length(responsepacket), true)
or:
writebuffer(pchar(responsepacket)^, length(responsepacket), true)
if client still not receiving response correctly, either not sending @ all, or not sending terminator client expecting. use packet sniffer, such wireshark, see client receiving, if anything.
Comments
Post a Comment