Android Question TCP Server app crashing during socket connection

ThiagoRodrigues

Member
Licensed User
Longtime User
I have designed a simple server app according to the code:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private server As ServerSocket
    Private astream As AsyncStreams
   
End Sub
Sub Service_Create
    ListenforConnections
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy

End Sub

Private Sub ListenforConnections
    server.Initialize(8889, "server")
    Log(server.GetMyWifiIP)
    Dim i As Boolean
    i = True
    'Do While i
        server.Listen
       
    'Loop
   
       
End Sub


Private Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
    Msgbox("Connected","")
    If astream.IsInitialized Then
        astream.Close
    End If

    astream.Initialize(NewSocket.InputStream, NewSocket.OutputStream, "astream")
   
    Dim s As String = "Connected"
    'astream.Write(s.GetBytes("UTF8"))
   
End If

End Sub

And then I start the service from Main.
When I try to connect to the server via socket TCP application (Windows), the Android app crashes.
I can´t find out why. What am I missing? I´m using B4A 3.0.
 
Top