B4J Tutorial [Server] Upload files from your B4A app to your B4J server over the internet

Status
Not open for further replies.

YIM bunchhat

Active Member
Licensed User
Longtime User
hello,...I tested but it doesn't work. when I start server on PC I got : Update DuckDNS: OK, when I test with your example I got Update DuckDNS: KO. When I send string form phone I got error. I already configure router port forward and open firewall. what's wrong? I use router TP-link
 

YIM bunchhat

Active Member
Licensed User
Longtime User
Hello I still cannot. I follow you by ip address I got as picture below. I configure my router like this is it correct?


On this point what you means and how to do it? call handle we need to add code to Main or not? Sorry I am new with coding
 

Attachments

  • Untitled.jpg
    48.3 KB · Views: 566
Last edited:

YIM bunchhat

Active Member
Licensed User
Longtime User
Here is your sample I modify it only on domain and token is it correct?
B4X:
Non-UI application (console application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: False
#End Region

Sub Process_Globals
    Private domain As String = "chhat"
    Private token As String = "07d52e48-f68a-4b47-85e8-1d7b7834106c"
    Private updateIp As Timer
    Private srvr As Server
    Public filesFolder As String = "uploaded"
End Sub

Sub AppStart (Args() As String)
    updateIp.Initialize("updateIp", 60 * 1000) '10 minutes
    updateIp.Enabled = True
    UpdateIp_Tick
    srvr.Initialize("srvr")
    srvr.Port = 54021
    File.MakeDir(File.DirApp, filesFolder)
    srvr.AddHandler("/upload", "Upload", False)
    srvr.AddHandler("/test", "Test", False)
    srvr.Start
    Log("Server started")
    StartMessageLoop
End Sub

Sub UpdateIp_Tick
    Dim j As HttpJob
    j.Initialize("j", Me)
    j.Download2("http://www.duckdns.org/update", Array As String("domains", domain, "token", token, _
        "ip", ""))
End Sub

Sub JobDone (j As HttpJob)
    If j.Success = True Then
        Log("Update DuckDNS: " & j.GetString)
    Else
        Log("Error updating Duck DNS: " & j.ErrorMessage)
    End If
    j.Release
End Sub
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
It is actually simpler than I wrote. The server handles "static" files automatically. You just need to put the files under the static files folder and they will be accessible. You do not need a custom handler for that.

Can server download file from internet and send it to client ?
I am thinking of making a small proxy .
What I tried is getting url from client in a handler class then download the file (http job) when job finishes I use File.Copy2(job.GetInputStream , ...) to write to resp.OutputStream .
But as you can see Sub Handle(req As ServletRequest, resp As ServletResponse) should have finished at that time
 

nonno

Active Member
Licensed User
Longtime User
Erel devo inviare un file txt di piccola dimensione tramite wifi da cellulare al pc
non riesco potresti darmi dei consigli( non sono programmatore conosco abbastanza il linguaggio VB6)
Grazie mille
 

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Hi
We are connected to internet through ADSL from ourl local ISP.
Our local ISP NAT-ing us, for example:
If i connected to the internet; my adsl modem got this ip 10.33.19.74 but if i checked my ip in google i got this different ip 109.200.183.132
From internet outside of my adsl i can't connected to our local server by following the above roles !

Any suggestion please ...
 

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
This is called carrier grade NAT (CGN). You will not be able to connect to your computer from outside unless your ISP provides you a real and unique IP address.

You should contact your ISP.
Our ISP doesn't respond to us!
Can we work around it?
when i using teamviewer, it work fine, Is their any solution exists like teamviewer ?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…