I have sucessfully sent a string to my Java Desktop application from my B4A app.
I'm using this code:
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 ?
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