PDA

View Full Version : Indy TCP sockets X Delphi XE8 (Android)



ironquark
14-03-2018, 05:40 PM
Hi

My code for Windows its working!!!

But for Android not, I'm using FireMonkey, here is my source code:

Server:

procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
MIRec: string;
begin
MIRec := AContext.Connection.IOHandler.ReadLn;
Memo1.Lines.Add('recebido = ' + MIRec);
end;

Client:


procedure TForm1.Button1Click(Sender: TObject);
begin
try
form1.IdTCPClient1.Host := 'localhost';
form1.IdTCPClient1.Port := 4040;
form1.IdTCPClient1.Connect;
except
ShowMessage('Connection Unsuccessful: ');
end;
form1.IdTCPClient1.IOHandler.WriteLn(edit1.text);
end;

What can be wrong on Android?

Thanks

SilverWarior
15-03-2018, 04:26 AM
Is your server also listening on LoclaHost or is it perhaps listening on your WiFi connection

According to SO question here (https://stackoverflow.com/questions/3590987/cant-use-serversocket-on-android) it seems that LocalHost address and WiFi address are not part of the same network. Acording to the answeres there local host IP address is usually specified as 127.0.0.1 while WiFi card is assigned to 0.0.0.0 IP address. So if Android is also using subnet mask 255.255.255.0 by default as it is on wondows then the two network addresses are not visible between each other since they are not part of the same network.

ironquark
15-03-2018, 12:48 PM
Is your server also listening on LoclaHost or is it perhaps listening on your WiFi connection

According to SO question here (https://stackoverflow.com/questions/3590987/cant-use-serversocket-on-android) it seems that LocalHost address and WiFi address are not part of the same network. Acording to the answeres there local host IP address is usually specified as 127.0.0.1 while WiFi card is assigned to 0.0.0.0 IP address. So if Android is also using subnet mask 255.255.255.0 by default as it is on wondows then the two network addresses are not visible between each other since they are not part of the same network.

Thank you my friend!!!

Changing to 0.0.0.0 on my android application its working!!!