|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
receive strings
Hi Guys!
my program has to send strings of text to a remote device and then recive strings by it; my problem is that I can't reive these strings, this is the procedure to send and (but it doesn't!) receive strings: procedure TfrmMain.memLogKeyPress(Sender: TObject; var Key: Char); var s: string; begin if Key = #13 then begin sockForward.Socket.SendText(memLog.Lines[memLog.Lines.Count - 1]); s:=sockForward.Socket.ReceiveText; AddLog('received message: ' + s); end; end; can you help me?? I send also the entire project! Thank You!! Christian |
|
#2
|
|||
|
|||
|
Quote:
What does it do? Does it hang, continue with a zero-length string, show garbage, ... ? Also, can we see a few lines of your sending function? M.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#3
|
|||
|
|||
|
Hirsch, thank you for replying!
the procedure that I wrote is the sending one!! simply, it doesn't work well, in fact when I press the enter key it sends the strings (the windows network icons flashes) but I receive nothing, no return messages!!! Can you help me?? Thank You. Christian |
|
#4
|
|||
|
|||
|
So that function is sending the text to itself?
Ok, that's probably why it doesn't work. Timing problems. The text is not yet in the receive buffer directly after sending it. Put the ReceiveText-part in a "OnClientRead" handler instead. It should work then. M. |
|
#5
|
|||
|
|||
|
can you give me an example of onclientread event handler please??
thank you!!! |
|
#6
|
|||
|
|||
|
This is code from one of my Delphi 5 projects, but the version should not matter:
Code:
procedure TChatClientForm.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
Memo1.Lines.Add('Client read from '+Socket.RemoteAddress+' data follows:');
while Socket.ReceiveLength>0 do begin
Memo1.Lines.Add('* '+Socket.ReceiveText);
end;
end;
Ah ja, and set the ClientType to "ctNonBlocking" to make it work. hth, M. |
|
#7
|
|||
|
|||
|
I think (if I understand the point of the procedure) that you must be holding a button down before anything will be sent or RECEIVED and also you must also be holding down a certain button.... This means for you to receive anything you must always be holding that button down....
If I havent understood the way the proc is working sorry for writing this ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > receive strings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|