Salve ragazzi
premetto che sto lavorando con la versione 3.2 beta3.
Non riesco a capire del perchè non riesco a ricevere nulla con connessioni ethernet sia con invio/ricezione byte che stringhe (quindi InputStrem/OutputStream e TextWriter/TextReader) con prove distinte.
Questa la prova con stringhe:
Poi in un Timer ho questo codice d'invio e ricezione:
L'errore in sb.Append è: android.os.NetworkOnMainThreadException
Ma non riesco a capire dove può essere l'errore perchè la connesione avviene e chi trasmette lo fà di sicuro perchè ho provato con Hyperterminal.
Grazie a tutti
premetto che sto lavorando con la versione 3.2 beta3.
Non riesco a capire del perchè non riesco a ricevere nulla con connessioni ethernet sia con invio/ricezione byte che stringhe (quindi InputStrem/OutputStream e TextWriter/TextReader) con prove distinte.
Questa la prova con stringhe:
B4X:
Sub Process_Globals
Dim socketp As Socket
Dim socketpserv As ServerSocket
Dim is As TextReader
Dim os As TextWriter
End Sub
Sub Globals
...............................
Dim ip_ As String
Dim porta_ As String
Dim connesso as Boolean
End Sub
#Region SOCKET
Sub Connetti(ip As String, porta As String)
Dim port As Int
If socketpserv.IsInitialized = False Then
socketpserv.Initialize(8234, "socketpserv")
socketpserv.Listen
ToastMessageShow("My IP: " & socketpserv.GetMyIP, True)
End If
If socketp.IsInitialized = False Then
socketp.Initialize("socketp")
If IsNumber(porta) Then port = porta
socketp.Connect(ip, port, 5000)
End If
End Sub
Sub socketp_Connected (Successful As Boolean)
Try
If Successful = False Then
ToastMessageShow("Errore connessione", False)
connesso = False
VisError
Return
End If
If is.IsInitialized = False Then is.Initialize(socketp.InputStream)
If os.IsInitialized = False Then os.Initialize(socketp.OutputStream)
connesso = True
Return
Catch As Exception
connesso = False
ToastMessageShow("Errore socket!", False)
End Try
End Sub
#End Region
Poi in un Timer ho questo codice d'invio e ricezione:
B4X:
.......
Timerp.Enable = False
os.WriteLine("Send prova" & Chr(13)) 'invio dati
'Attesa
Sleep(100) 'è una mia routine di ritardo
Dim sb As StringBuilder
sb.Append(is.ReadLine) '< qui compare l'Errore
Do While is.Ready
sb.Append(is.ReadLine)
Loop
...........
L'errore in sb.Append è: android.os.NetworkOnMainThreadException
Ma non riesco a capire dove può essere l'errore perchè la connesione avviene e chi trasmette lo fà di sicuro perchè ho provato con Hyperterminal.
Grazie a tutti
Last edited: