Android Question Socket: How to receve data after sending...

Vinians2006

Active Member
Licensed User
I have sucessfully sent a string to my Java Desktop application from my B4A app.
I'm using this code:
B4X:
Sub btnEnviar_Click
   cliente.Initialize("cliente")
   cliente.Connect("192.168.0.101", 9000, 10000)
End Sub

Sub cliente_Connected (Successful As Boolean)
   If (Successful) Then
     Dim out As OutputStream
     Dim inp As InputStream
     Dim len As Int
     Dim buffer(255) As Byte
     Dim ret As String
   
     out = cliente.OutputStream
     inp = cliente.InputStream
   
     Dim texto As String
     texto = edtString.Text
     texto = NumberFormat2(texto.Length,4,0,0,False) & texto
     len = texto.Length
     ' Send data (working)
     out.WriteBytes(texto.GetBytes("ASCII"), 0, len)
   
     ' Get response (not working)
     ret = ""
     If (inp.BytesAvailable > 0) Then
       inp.ReadBytes(buffer, 0, buffer.length)
       ret = BytesToString(buffer, 0, buffer.Length, "ASCII")
     End If
     edtString.Text = ret
     cliente.close
   Else
     ToastMessageShow("Erro conectando", True)
   End If
End Sub
My Java server, returns the "OK" string, but I didnt found the name of the event that I need to receive the server response, so I placed directly after sending information. I know its wrong, but whats the name of the event ?
 

Vinians2006

Active Member
Licensed User
Thanks Erel. But, if I want to use this way how can I should proceed to use it without using AsyncStream?????
 

Vinians2006

Active Member
Licensed User
Ok, but using this library I can send individual bytes over TCP/IP (same network) ?
And where do I find this library ? The link on then tutorial is broken...
Thanks!
 
Top