Android Question Send a text via Internet between two tablets

adrianstanescu85

Active Member
Licensed User
Longtime User
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:

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
 

sorex

Expert
Licensed User
Longtime User
you have routers and firewalls to pass. you'll need port forwardings to your device to get it working.
 
Upvote 0

adrianstanescu85

Active Member
Licensed User
Longtime User
I'm not connected to my WiFi generally, since that's not necessary, so there's no place for routers and firewalls.

During my unsuccessful tests I was using ONLY my mobile data connection (3G) on both tablets. Is there anything to be bypassed there?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
never tried it like that but providers might block some none traditional (none http,https,ftp,telnet,...) ports for security reasons.

usually everything below 1024 is open, try with port 80, 21 or something like that.
 
Upvote 0

adrianstanescu85

Active Member
Licensed User
Longtime User
That may be the case, but when switching from port 5000 to port 500, this is below the 1024 limit, I get the following error:

java.net.BindException: bind failed: EACCES (Permission denied)

I went to and added
<uses-permissionandroid:name="android.permission.INTERNET"/>
to the Manifest, but... no changes!

Any solutions?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
providers might block some none traditional (none http,https,ftp,telnet,...) ports for security reasons.
Not to mention the proxy used by most 3G/4G providers. The solution which works 100% is the use of a "reflector" where each app get and post data (you'll need at least a shared hosting).
 
Upvote 0

adrianstanescu85

Active Member
Licensed User
Longtime User
The MQTT library is a very good idea, I've tried it, but I get a latency of about 500-1000 miliseconds and the data flow is stopped between text sendings.

Not to mention the proxy used by most 3G/4G providers. The solution which works 100% is the use of a "reflector" where each app get and post data (you'll need at least a shared hosting).

What do you mean by that?
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
500 millisecond is a good latency time over internet to send a message
 
Upvote 0

adrianstanescu85

Active Member
Licensed User
Longtime User
True, but I believe a continuous stream can be achieved, true? Not much of a bandwidth, I'm not interested in that, I just need to send like a letter after each letter as a Seekbar dragged with the finger changes its value.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Adrian,
As I have told you previously, the solution which works 100% is to create a "reflector" from a web site where your apps will post data and get data.
This is done by creating your own script to receive : the ID of the sender, the ID of the receiver and the message. The script will have to store those data. Your apps will have to make regularly a connection to the reflector to check if there is some message waiting.
 
Upvote 0

adrianstanescu85

Active Member
Licensed User
Longtime User
I wouldn't bother with a true direct connection, not the possible interruptions either, what I basically need is to remote control one device from another by internet, this is why I asked.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Get a cheap hoster (php + MySql). It's very easy to handle over httputils2.

The workflow is:

App1 -> httputils -> TCP/IP -> WWW -> YourDomain -> php script -> MySql and back to App2 - APPn

Benefits:

- you don't care about the ip address (all automatic)
- easy to handle
- you can handle users by setting up passwords and other stuff
- data can be encrypted

For about 5-10 US$ a month (this is the "negative" thing, maybe you find a free hoster) you can build very nice apps.
 
Upvote 0

adrianstanescu85

Active Member
Licensed User
Longtime User
Now that you mentioned this...I figure I already have a dedicated domain that actually works with ASP.NET apps, this is the place where I store my web apps. So I can build another one where to post the data. What about retrieving? Which option do you think would be the least bandwidth consuming for sending and receiving data this way?
 
Upvote 0

adrianstanescu85

Active Member
Licensed User
Longtime User
I need fast response times, somewhat like the MQTT has, but if I go with a classical timer listening from my server that would actually mean data traffic each... let's say half a second. I'd very much like something like push info.
 
Upvote 0
Top