Hi everyone!
I was trying to exchange a string between two devices, but i can't.
I've readed the network library documentation and the example, but the example doesn't work on my device. (I supose the problem is that i don't know how to use it correctly) and i don't understand at all how the network library works... I'm :sign0104: at this things...
Here is the code i was trying to use :
Thanks in advance!
I was trying to exchange a string between two devices, but i can't.
I've readed the network library documentation and the example, but the example doesn't work on my device. (I supose the problem is that i don't know how to use it correctly) and i don't understand at all how the network library works... I'm :sign0104: at this things...
Here is the code i was trying to use :
B4X:
Sub Process_Globals
Dim SKT As Socket
Dim MySKT As Socket
Dim SSK As ServerSocket
Dim ASync As AsyncStreams
Dim READ As InputStream
Dim SEND As OutputStream
Dim buffer() As Byte
End Sub
Sub Globals
Dim txt_msg As EditText
Dim cmd_send,cmd_conect As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
If SSK.IsInitialized = False Then
SSK.Initialize(8558,"SSK")
SSK.Listen
End If
End Sub
Sub SSK_NewConnection (Successful As Boolean, NewSocket As Socket)
READ = NewSocket.InputStream
SEND = NewSocket.OutputStream
ASync.InitializePrefix(READ,True,SEND,"AStreams")
SKT = NewSocket
SSK.Listen
Msgbox("ServerSocket conected","")
End Sub
Sub MySKT_Connected (Successful As Boolean)
Msgbox("Socket conected","")
End Sub
Sub AStreams_NewData (Newbuffer() As Byte)
READ.ReadBytes(Newbuffer,0,Newbuffer.Length)
Msgbox(BytesToString(Newbuffer,0,Newbuffer.Length,"UTF-8"),"")
End Sub
Sub AStreams_Error
ToastMessageShow("Error in ASync",False)
End Sub
Sub cmd_send_click
buffer = txt_msg.Text.GetBytes("UTF-8")
SEND.WriteBytes(buffer,0,buffer.Length)
End Sub
Sub cmd_conectar_click
If MySKT.IsInitialized Then MySKT.Close
MySKT.Initialize("MySKT")
MySKT.Connect(SSK.GetMyIP,8558,0)
End Sub
Sub Activity_Pause(UserClosed As Boolean)
If UserClosed Then
SKT.Close
MySKT.Close
SSK.Close
End If
End Sub
Thanks in advance!