Hi everybody
I am using the wifi connections to send text data to other device.
This is working well on some devices, but there are problems in others.
Usually happens to lack of data transmission when the device is not unrooted. Below is a sample test done between 2 devices.
i.g. 01:
Rooted cell phone (server listening on port 2222) - unrooted device.
unrooted device (client) message: Successfully connected
rooted device (server) message: Connected.
data transmition OK
UnRooted cell phone (server listening on port 2222) - Rooted device (client).
Rooted device (client) message: Successfully connected
UnRooted device (server) message: NO MESSAGE
data transmition - Fail
How can I solve it?
I am using the wifi connections to send text data to other device.
This is working well on some devices, but there are problems in others.
Usually happens to lack of data transmission when the device is not unrooted. Below is a sample test done between 2 devices.
i.g. 01:
Rooted cell phone (server listening on port 2222) - unrooted device.
unrooted device (client) message: Successfully connected
rooted device (server) message: Connected.
data transmition OK
UnRooted cell phone (server listening on port 2222) - Rooted device (client).
Rooted device (client) message: Successfully connected
UnRooted device (server) message: NO MESSAGE
data transmition - Fail
How can I solve it?
B4X:
'Activity module
Sub Process_Globals
Dim Server As ServerSocket
Dim ClientSocket As Socket
Dim AStream As AsyncStreams '
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Display")
If FirstTime Then
Server.Initialize(2222, "Server")
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Close_Click
If ClientSocket.Connected Then
Astream.Close
ClientSocket.Close
End If
End Sub
Sub ServerClick_Click
Server.Listen
End Sub
Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
ToastMessageShow("Connected", False)
Socket1 = NewSocket
AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
Else
ToastMessageShow(LastException.Message, True)
End If
Server.Listen
End Sub
Sub Connect_Click
If Not(ClientSocket.IsInitialized) Then
ClientSocket.Initialize("ClientSocket")
End If
ClientSocket.Connect("192.168.154.85", 2222, 2000)
End Sub
Sub ClientSocket_Connected (Successful As Boolean)
If Successful Then
AStream.Initialize(ClientSocket.InputStream,
ClientSocket.OutputStream, "AStreams")
ToastMessageShow("Successfully connected", True)
Else
ToastMessageShow("No connection!", True)
End If
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
ToastMessageShow(msg, False)
Log(msg)
End Sub