Hello
I tried to put up a simple app that I can run on both of my mobile devices so that with a click of a button I could be able to send a text from one tablet to the other via Internet.
I'm not really interested in a specific protocol to do this, I basically need this to work in any way.
I put up a simple layout with an EditText where I should write the target's IP address, and a Button that should send a text (any text basically) to the device with that IP address. There's also a Label that holds each device's IP address. I do have to say that those IP addresses that are show are most likely incorrect (checked by free online services through the Internet browser).
Here's what I modified from the samples I read:
To my disappointment, this only works on my local network and NOT via Internet! I tried using both the IP that's listed by the Label as well as the IP shown by online services, nothing works!
Any idea why?
Any suggestions on how to do this (maybe even change the protocol if necessary)?
Thank you!
Adrian
I tried to put up a simple app that I can run on both of my mobile devices so that with a click of a button I could be able to send a text from one tablet to the other via Internet.
I'm not really interested in a specific protocol to do this, I basically need this to work in any way.
I put up a simple layout with an EditText where I should write the target's IP address, and a Button that should send a text (any text basically) to the device with that IP address. There's also a Label that holds each device's IP address. I do have to say that those IP addresses that are show are most likely incorrect (checked by free online services through the Internet browser).
Here's what I modified from the samples I read:
B4X:
#Region Project Attributes
#ApplicationLabel: UDP
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: Portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: True
#IncludeTitle: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim UDP1 As UDPSocket
Dim SS As ServerSocket
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Label1 As Label
Dim EditText1 As EditText
Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
Label1.Text = SS.GetMyIP
If FirstTime Then
UDP1.Initialize("UDP", 5000, 8192)
ToastMessageShow("Receiving...", False)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Dim Packet As UDPPacket
Dim data() As Byte
data = "test test test".GetBytes("UTF8")
Packet.Initialize(data, EditText1.Text, 5000)
UDP1.Send(Packet)
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
Msgbox("Message received: " & msg, "")
End Sub
To my disappointment, this only works on my local network and NOT via Internet! I tried using both the IP that's listed by the Label as well as the IP shown by online services, nothing works!
Any idea why?
Any suggestions on how to do this (maybe even change the protocol if necessary)?
Thank you!
Adrian