Android Question TCP Socket and OutputStream

robertyoungs

Member
Licensed User
Longtime User
I'm sure I'm probably missing the obvious in this simple test, but although I can see the app make a connection on the server side and then immediately close it, it does not transfer the string.

Apols if this has already been covered elsewhere, but I can't seem to find anything to help - I'd be eternally grateful for any pointers!

B4X:
Sub Process_Globals
   
End Sub

Sub Globals
    Dim tw As TextWriter
    Dim Socket1 As Socket
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
    Socket1.Initialize("Socket1")
    Socket1.Connect("192.168.1.84", 50007, 20000)
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Socket1_Connected (Successful As Boolean)
    If Successful = False Then
        Msgbox(LastException.Message, "Error connecting")
        Return
    End If
    ToastMessageShow("Connected successfully", False)
    tw.Initialize(Socket1.OutputStream)
    tw.Writeline("test string" & CRLF)
       
    Socket1.Close
End Sub
 
Top