Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IdTCPClient on Android: Connecting to non-active network
#12
(05-08-2018, 05:12 PM)rlebeau Wrote: An AV at a memory address near 0 usually means you are accessing a nil pointer.  My guess would be the TIdTCPClient's Socket.Binding object hasn't been created yet when you call setsockopt().  Try moving that call into the TIdTCPClient's OnSocketAllocated or OnAfterBind event instead.  That ensures the Socket.Binding object and its socket Handle are both ready for use.

Okay. Fixed the AV. Now I have a socket error:
Code:
procedure TTCPThread.IdTCPClient1OnAfterBind(ASender: TObject);
var
 M: TMarshaller;
begin
 LocalLog('IdTCPClient: OnAfterBind: ');
 if NetworkData.LocalIP <> '' then
 begin
   try
     if NetworkData.WIFIInterface <> '' then
     begin
       if NOT assigned(GStack) then // just checking...
       begin
         LocalLog('IdTCPClient: GStack is not assigned!',d_error);
         exit;
       end;
       LocalLog('IdTCPClient1.Socket.Binding.Handle='+IntToStr(IdTCPClient1.Socket.Binding.Handle)); // Result: "42"
       GStack.CheckForSocketError(
         Posix.SysSocket.setsockopt(
         IdTCPClient1.Socket.Binding.Handle,
         Id_SOL_SOCKET,
         SO_BINDTODEVICE,
         M.AsAnsi(NetworkData.WIFIInterface).ToPointer^,
         Length(NetworkData.WIFIInterface)+1 // assuming the device name uses ASCII chars only
         )
       );
     end;
   except
     on E:Exception do LocalLog('TCPThread: GStack failed: WIFIInterface='+NetworkData.WIFIInterface
       +' Length(WIFIInterface)='+IntToStr(length(NetworkData.WIFIInterface))
       +': '+E.Message,d_error);
   end;
 end; // ELSE: We are now using the Android Active Network, whatever that may be.

end;


This generates:

IdTCPClient1.Socket.Binding.Handle=42
ERROR: TCPThread: GStack failed: WIFIInterface=wlan0 Length(WIFIInterface)=5: Socket Error # 1

I do hope we are not in a situation where Android somehow blocks any attempt to connect to a 'non-active network'.
But if this is at Linux level, how could that be?
So, the WIFI IS connected (enabled) and the name 'wlan0' is valid, as I can see a lot of data passing through the Android debug window

PS, this is what the unfiltered Android Log looks like. There is no other issue reported by Android during the call with GStack.
You can see the WIFI is connected to my test WIFI (with no Internet) called "SARTrack_SAT" on interface "wlan0"
Code:
45: I/info(16249): SARTrack Service: [S] D3: IdTCPClient: OnSocketAllocated:
05-09 15:28:17.547: I/info(16249): SARTrack Service: [S] D3: IdTCPClient: OnAfterBind:
05-09 15:28:17.549: I/info(16249): SARTrack Service: [S] D3: IdTCPClient1.Socket.Binding.Handle=46
05-09 15:28:17.551: E/error(16249): SARTrack Service: ERROR: [S] ERROR: TCPThread: GStack failed: WIFIInterface=wlan0 Length(WIFIInterface)=5: Socket Error # 1
05-09 15:28:17.552: I/info(16249): SARTrack Service: [S] D3: SSL Status: 1  Connecting to 192.168.53.104.
05-09 15:28:18.131: D/WifiStateMachine(1613):  ConnectedState !CMD_RSSI_POLL  rt=10152611/10711287 18 0 "SARTrack_SAT" c8:3a:35:15:10:28 rssi=-39 f=2437 sc=60 link=11 tx=0.2, 0.0, 0.0  rx=0.7 bcn=0 [on:0 tx:0 rx:0 period:3000] from screen [on:0 period:1159108051] hn rssi=-34 ag=0 hr ls-=0 [56,56,56,56,61] brc=0 lrc=0 offload-stopped
05-09 15:28:18.132: D/WifiStateMachine(1613):  L2ConnectedState !CMD_RSSI_POLL  rt=10152612/10711288 18 0 "SARTrack_SAT" c8:3a:35:15:10:28 rssi=-39 f=2437 sc=60 link=11 tx=0.2, 0.0, 0.0  rx=0.7 bcn=0 [on:0 tx:0 rx:0 period:1] from screen [on:0 period:1159108052] hn rssi=-34 ag=0 hr ls-=0 [56,56,56,56,61] brc=0 lrc=0 offload-stopped
05-09 15:28:18.133: D/WifiStateMachine(1613):  get link layer stats 0
05-09 15:28:18.133: D/WifiNative-wlan0(1613): doString: [SIGNAL_POLL]
05-09 15:28:18.134: D/wpa_supplicant(1852): wlan0: Control interface command 'SIGNAL_POLL'
05-09 15:28:18.151: D/WifiStateMachine(1613): fetchRssiLinkSpeedAndFrequencyNative rssi=-40 linkspeed=11 freq=2437
05-09 15:28:18.151: D/WifiConfigManager(1613): updateConfiguration freq=2437 BSSID=c8:3a:35:15:10:28 RSSI=-39 "SARTrack_SAT"WPA_PSK
05-09 15:28:18.151: D/WifiStateMachine(1613): calculateWifiScore freq=2437 speed=11 score=60 highRSSI  -> txbadrate=0.00 txgoodrate=0.09 txretriesrate=0.00 rxrate=0.34 userTriggerdPenalty0
05-09 15:28:18.151: D/WifiStateMachine(1613):  good link -> stuck count =0
05-09 15:28:18.151: D/WifiStateMachine(1613):  badRSSI count0 lowRSSI count0 --> score 56
05-09 15:28:18.151: D/WifiStateMachine(1613):  isHighRSSI       ---> score=61
05-09 15:28:18.153: I/QCNEJ(2313): |CORE| CNE received action RSSI/Link Changed events: android.net.wifi.RSSI_CHANGED
05-09 15:28:18.153: D/QCNEJ(2313): |CORE| Updating RSSI: -40
05-09 15:28:18.153: I/QCNEJ(2313): |PB_MSG| sendWifiStatus - subType: 101 networkState: 1 wifiState: 3 rssi=-40 freqBand = _2GHz ssid=SARTrack_SAT bssid=c8:3a:35:15:10:28 ipV4Addr=192.168.53.100 ifNameV4=wlan0 ipAddrV6= ifNameV6= timeStamp:2018-05-09 15:28:18.153 net handle=446693034718 isAndroidValidated = false DNS addrs= 212.56.224.40, 212.56.224.41, 0.0.0.0, 0.0.0.0,
05-09 15:28:21.153: D/WifiStateMachine(1613):  ConnectedState !CMD_RSSI_POLL  rt=10155633/10714309 18 0 "SARTrack_SAT" c8:3a:35:15:10:28 rssi=-40 f=2437 sc=60 link=11 tx=0.1, 0.0, 0.0  rx=0.3 bcn=0 [on:0 tx:0 rx:0 period:3000] from screen [on:0 period:1159111073] hn rssi=-35 ag=0 hr ls-=0 [56,56,56,56,61] brc=0 lrc=0 offload-stopped
05-09 15:28:2


Bart
---
Bart Kindt
CEO and Developer
SARTrack Limited
New Zealand
www.sartrack.nz
Reply


Messages In This Thread
RE: IdTCPClient on Android: Connecting to non-active network - by BartKindt - 05-09-2018, 01:36 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)