TCP Socket Issue

Syndad

Member
Licensed User
Longtime User
I am having a problem with Sockets. First off I cannot use Asyncstream as I am connecting to an existing program and cannot rewrite it. So i must use Sockets. I need to open a socket (no problem) and send a command to the server (this also works) I then need to retrieve a response from the Server. From what I can see the program will send the command only if I tw.close or TCPSocket.close. But If I do that it cannot receive the response.

B4X:
Sub TCPSocket_Connected (Successful As Boolean)
   If Successful = False Then
      ToastMessageShow("Connection Failed",False)
   End If
   Dim tw As TextWriter
   Dim StringIn As String
   
   tw.Initialize(TCPSocket.OutputStream)
   tw.WriteLine(TCPPacketToSend)
   tw.Flush
   'tw.Close ' this will allow the server to receive command
   Dim tr As TextReader
   tr.Initialize(TCPSocket.InputStream)
   
   StringIn = tr.ReadAll
   
   Msgbox(StringIn,"")
   
   TCPSocket.Close
End Sub
 

Syndad

Member
Licensed User
Longtime User
Found My own answer needed.
Changed tw.WriteLine(TCPPacketToSend) to
tw.writeline(TCPPacketToSend & chr(13))
 
Upvote 0
Top