Remy,
Trying to set the outgoing network using the allocated IP address does not work.
This is what I got:
Using Delphi 10.2.3 and the default installation Indy10 10.6.2.5366
Testing on my Android 7.0 phone.
State:
- Mobile Network connected with Internet access. "Active Network" is the Mobile network.
- WIFI is enabled, the assigned IP address is 192.168.53.102
- My Local Database Server is connected to the WIFI network, and broadcasts its own IP address via the IdUDPServer (which I receive on the phone via the WIFI). Its IP address is 192.168.53.101
{code}
IdTCPClient1 := TIdTCPClient.Create(nil);
with IdTCPClient1 do
begin
OnConnected := IdTCPClient1Connected;
OnDisconnected := IdTCPClient1Disconnected;
OnStatus := IdTCPClient1Status;
IdTCPClient1.OnSocketAllocated := IdTCPClient1OnSocketAllocated;
end;
try
IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmClient; // sslmUnassigned
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.SSLVersions := [sslvTLSv1_2];
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1_2;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyDepth := 0;
IdSSLIOHandlerSocketOpenSSL1.OnStatusInfo := IdSSLIOHandlerSocketOpenSSL1StatusInfo;
IdSSLIOHandlerSocketOpenSSL1.OnStatus := IdSSLIOHandlerSocketOpenSSL1Status;
IdSSLIOHandlerSocketOpenSSL1.OnVerifyPeer := IdSSLIOHandlerSocketOpenSSL1VerifyPeer;
IdSSLIOHandlerSocketOpenSSL1.PassThrough := true;
IdTCPClient1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
IdOpenSSLSetLibPath(DirNames.SSLDir);
except
on E:Exception do
begin
LocalLog('TCPThread.Execute: Creating IdSSLIOHandlerSocketOpenSSL: '+E.Message,d_error);
sleep(1000);
continue; // Main Loop
end;
end;
try // finally
try // except
with IdTCPClient1 do
begin
if NetworkData.LocalIP <> '' then
begin
BoundIP := NetworkData.LocalIP;
BoundPort := 8051;
LocalLog('=== TCPThread.Execute: Connect using BoundIP: '+NetworkData.LocalIP);
end;
host := NetworkData.DTBActiveServer;
port := Communications.DTBPort2;
ConnectTimeout := 10000; // Increased from 5000 to 10000 29-12-2016 v09768
SARTrackServiceDM.SetDTBConnectStatus(IS_CONNECTPENDING);
LocalLog('TCPThread.Execute: DTB Client trying connect to ' + host + ' on port ' + IntToStr(port));
UAndroidPowerManagement.AcquireWakeLock;
Connect;
UAndroidPowerManagement.ReleaseWakeLock;
end;
except
on E: Exception do
begin
LocalLog('TCPThread.Execute: During Connect:'+ E.Message,d_error);
SARTrackServiceDM.SetDTBConnectStatus(IS_DISCONNECTED);
{code}
The Connect attempt is not going out over the WIFI network. It probably goes out over the Mobile network.
Reading all the documentation on the SetSockOpt() has unfortunately not helped me much, I do not understand much of it.
The Indy SetSockOpt() requires 3 integers.
The Linux doc talks about the SO_BINDTODEVICE; Which I assume is Constant?, which I cannot find anywhere.
"SO_BINDTODEVICE: Bind this socket to a particular device like "eth0", as specified in the passed interface name."
So where do I enter this string?
And unfortunately I have still not been able to find any type of Android string or integer reference linked to a given Network, so that I can supply this to Indy. The only thing I get is the assigned IP address. (or lots of information about bandwidth, frequencies, etc.)
CORRECTION: I did find this:
"getNetworkId
int getNetworkId ()
Each configured network has a unique small integer ID, used to identify the network when performing operations on the supplicant. This method returns the ID for the currently connected network."
But no string name, and I am not sure if the ID is a Linux or internal Android ID.
I do have the MAC address.
If you could give me some example on how to use the SetSockOpt() or any other way of setting the required network, would be great...
Bart
Trying to set the outgoing network using the allocated IP address does not work.
This is what I got:
Using Delphi 10.2.3 and the default installation Indy10 10.6.2.5366
Testing on my Android 7.0 phone.
State:
- Mobile Network connected with Internet access. "Active Network" is the Mobile network.
- WIFI is enabled, the assigned IP address is 192.168.53.102
- My Local Database Server is connected to the WIFI network, and broadcasts its own IP address via the IdUDPServer (which I receive on the phone via the WIFI). Its IP address is 192.168.53.101
{code}
IdTCPClient1 := TIdTCPClient.Create(nil);
with IdTCPClient1 do
begin
OnConnected := IdTCPClient1Connected;
OnDisconnected := IdTCPClient1Disconnected;
OnStatus := IdTCPClient1Status;
IdTCPClient1.OnSocketAllocated := IdTCPClient1OnSocketAllocated;
end;
try
IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmClient; // sslmUnassigned
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.SSLVersions := [sslvTLSv1_2];
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1_2;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyDepth := 0;
IdSSLIOHandlerSocketOpenSSL1.OnStatusInfo := IdSSLIOHandlerSocketOpenSSL1StatusInfo;
IdSSLIOHandlerSocketOpenSSL1.OnStatus := IdSSLIOHandlerSocketOpenSSL1Status;
IdSSLIOHandlerSocketOpenSSL1.OnVerifyPeer := IdSSLIOHandlerSocketOpenSSL1VerifyPeer;
IdSSLIOHandlerSocketOpenSSL1.PassThrough := true;
IdTCPClient1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
IdOpenSSLSetLibPath(DirNames.SSLDir);
except
on E:Exception do
begin
LocalLog('TCPThread.Execute: Creating IdSSLIOHandlerSocketOpenSSL: '+E.Message,d_error);
sleep(1000);
continue; // Main Loop
end;
end;
try // finally
try // except
with IdTCPClient1 do
begin
if NetworkData.LocalIP <> '' then
begin
BoundIP := NetworkData.LocalIP;
BoundPort := 8051;
LocalLog('=== TCPThread.Execute: Connect using BoundIP: '+NetworkData.LocalIP);
end;
host := NetworkData.DTBActiveServer;
port := Communications.DTBPort2;
ConnectTimeout := 10000; // Increased from 5000 to 10000 29-12-2016 v09768
SARTrackServiceDM.SetDTBConnectStatus(IS_CONNECTPENDING);
LocalLog('TCPThread.Execute: DTB Client trying connect to ' + host + ' on port ' + IntToStr(port));
UAndroidPowerManagement.AcquireWakeLock;
Connect;
UAndroidPowerManagement.ReleaseWakeLock;
end;
except
on E: Exception do
begin
LocalLog('TCPThread.Execute: During Connect:'+ E.Message,d_error);
SARTrackServiceDM.SetDTBConnectStatus(IS_DISCONNECTED);
{code}
The Connect attempt is not going out over the WIFI network. It probably goes out over the Mobile network.
Reading all the documentation on the SetSockOpt() has unfortunately not helped me much, I do not understand much of it.
The Indy SetSockOpt() requires 3 integers.
The Linux doc talks about the SO_BINDTODEVICE; Which I assume is Constant?, which I cannot find anywhere.
"SO_BINDTODEVICE: Bind this socket to a particular device like "eth0", as specified in the passed interface name."
So where do I enter this string?
And unfortunately I have still not been able to find any type of Android string or integer reference linked to a given Network, so that I can supply this to Indy. The only thing I get is the assigned IP address. (or lots of information about bandwidth, frequencies, etc.)
CORRECTION: I did find this:
"getNetworkId
int getNetworkId ()
Each configured network has a unique small integer ID, used to identify the network when performing operations on the supplicant. This method returns the ID for the currently connected network."
But no string name, and I am not sure if the ID is a Linux or internal Android ID.
I do have the MAC address.
If you could give me some example on how to use the SetSockOpt() or any other way of setting the required network, would be great...
Bart