Reputation: 947
I had a socket communication with a Python server using TClientSocket. After realizing I couldn't have more than on client using TClientSocket I decided to use INDY. I made a little test app using Delphi Indy for the client and server. This worked.
However it now does not work with Python. Python receives connection and the messages just fine, but when it responds, my Delphi gets nothing. My call to fIdTCPClient1.IOHandler.ReadLn() just sits there forever.
Is there something special you have to do to send messages to INDY from a non INDY Server?
procedure TForm3.Button3Click(Sender: TObject);
begin
fIdTCPClient1 := TIdTCPClient.Create(nil);
fIdTCPClient1.Port := 20200;
fIdTCPClient1.Host := '127.0.0.1';//'localhost';
fIdTCPClient1.Connect;
fIdTCPClient1.IOHandler.WriteLn('You there');
msg := fIdTCPClient1.IOHandler.ReadLn();
ShowMessage(msg);
end;
Connection on the Python side
HOST = '127.0.0.1' # Localhost
PORT = 20200
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((HOST, PORT))
s.listen(1)
except socket.error:
s.close()
s = None
return -1
Python Send/Recieve
data = conn.recv(4096).strip()
print data
conn.send('I am here')
Upvotes: 2
Views: 3322
Reputation: 11
Function IdTCPClient1.IOHandler.ReadLn()
hang and wait until receive "end of line" (#13#10
or \r\n
) from server. Add on server side response with \r\n
at end.
Upvotes: 1