AsyncStreams: I can't write on socket nore than once.

claudio

Member
Licensed User
Longtime User
I wrote a Socket client app which communicate with a server on my PC writted in Python.

It works fine, I can send data and receive the answer, but I can send data only once and after that all sends fails and I must disconnect and reconnect to the server.

Here my code:

B4X:
Sub Socket1_Connected (Successful As Boolean)
   If Successful = False Then
      lConnect.Text = "Not connected!"
      Return
   End If
   lConnect.Text = "Connected!"
   AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
End Sub

Sub bSend_Click
   If Socket1.Connected = False Then
      ToastMessageShow("Not connected!", False)
      Return
   End If
   Dim buffer() As Byte = eSend.Text.GetBytes("UTF8")
   If AStreams.Write(buffer) == False Then ToastMessageShow("Data not written!",False)
End Sub

Sub AStreams_NewData (Buffer() As Byte)
    Dim msg As String
    msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    lResult.Text = msg
End Sub

the row:

B4X:
   If AStreams.Write(buffer) == False Then ToastMessageShow("Data not written!",False)

show the Toast Message after the first time. there is a way to reset the AsyncStreams ?

Thanks
Claudio
 
Top