I'm trying to convert my Android app from using Bluetooth to WIFI. I've been following the Asynch Streams sample and came up with the following two modules. The first module uses sockets to try to connect to a service on another phone. It times out after 10 seconds with Success = False. The second code section is the service. It never moves beyond Server.Listen. The Sub Server_NewConnection is never triggered. What am I doing wrong?
B4X:
Sub Process_Globals
Dim Socket1 As Socket
End Sub
Sub Activity_Create(FirstTime As Boolean)
Socket1.Initialize("Socket1")
End Sub
Sub Doit
MacAddress = "192.168.2.8"
Try
ProgressDialogShow("Loading Profile ")
Socket1.Connect(MacAddress,5500,10000)
Catch
Log("WIFI Loader failed: " & LastException.Message)
End Try
End Sub
Sub Socket1_Connected (Success As Boolean)
Log("WIProfileLoader connected: " & Success)
If Success = False Then
Msgbox("No Connection","")
Socket1.close
AStream.Close
Activity.Finish
StartActivity("DisplayMatches")
End If
.....
B4X:
'this is the server service
Sub Process_Globals
Dim Server As ServerSocket
Dim Socket1 As Socket
End Sub
Sub Service_Create
Server.Initialize(5500, "Server")
End Sub
Sub Service_Start(StartingIntent As Intent)
Log("WIFI Listener Service is starting")
serial1.Initialize("serial1")
Try
ServicePass = ServicePass + 1
Server.Listen
Catch
Log(LastException.message)
End Try
End Sub
Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful = True Then
Log("WIFI connection successful")
Socket1 = NewSocket
Try
If Astream.IsInitialized = False Then
Astream.InitializePrefix(Socket1.InputStream, False, Socket1.OutputStream, "AStream")
End If
Catch
Log(LastException.message)
End Try
Else
Log("WIFI Listener failed")
End If
...