Android Question Network v1.51 , i Always Successful !?

alan1968

Active Member
Licensed User
Longtime User
Hi ALL ! :)

i have a problem with network V1.51 , I always Successful ,no matter the IP address !?

i cheked in 4.3 and 5.0 same thing !

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
  
    Private so As Socket                    ' Network Lib v1.51

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
    Private ConnectButton As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ConnectButton.Initialize("ConnectButton")
    ConnectButton.Text="Connect"
    Activity.AddView(ConnectButton,20dip,20dip,200dip,50dip)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub so_Connected (Successful As Boolean)
    If Successful Then
        Log("Connection Successful")
    Else
        Log("Connection Failed")
        Log(LastException)
    End If
End Sub



Sub ConnectButton_Click
    so.Initialize("so")
    so.Connect("192.168.1.1",502, 0)
End Sub
 

M. Giray Ozkan

Member
Licensed User
Longtime User
I've tried your code on my android phone (Android 5.0.2) and I got an error as expected

Connection Failed
(ErrnoException) android.system.ErrnoException: connect failed: EHOSTUNREACH (No route to host)
 
Upvote 0

alan1968

Active Member
Licensed User
Longtime User
in 3G
B4X:
Sub ConnectButton_Click
    Dim ip As Int
    ip=Rnd(1,254)
    so.Initialize("so")
    so.Connect(ip &".11.228.89",102, 10000)
End Sub

log:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Connection Successful
Connection Successful
Connection Successful
Connection Successful
Connection Successful
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Connection Failed
(SocketTimeoutException) java.net.SocketTimeoutException: failed to connect to /245.11.228.89 (port 502) after 10000ms
Connection Successful
Connection Successful
Connection Failed
(SocketTimeoutException) java.net.SocketTimeoutException: failed to connect to /248.11.228.89 (port 502) after 10000ms
Connection Successful
Connection Successful
Connection Successful

ddm log
03-19 09:18:40.159: I/System.out(4051): [CDS][DNS] getAllByNameImpl netId = 0
03-19 09:18:40.160: I/System.out(4051): [socket][11] connection /9.11.228.89:502;LocalPort=39730(10000)
03-19 09:18:40.160: I/System.out(4051): [CDS]connect[/9.11.228.89:502] tm:10
03-19 09:18:40.762: I/System.out(4051): [socket][/100.98.81.61:39730] connected
03-19 09:18:40.763: I/System.out(4051): [CDS]close[39730]

very strange !!!
 
Upvote 0

alan1968

Active Member
Licensed User
Longtime User
more DDM log
03-19 09:39:31.003: I/System.out(4051): [CDS][DNS] getAllByNameImpl netId = 0
03-19 09:39:31.004: I/System.out(4051): [socket][21] connection /10.11.228.89:502;LocalPort=40044(10000)
03-19 09:39:31.005: I/System.out(4051): [CDS]connect[/10.11.228.89:502] tm:10
03-19 09:39:31.050: I/System.out(4051): [socket][/100.98.81.61:40044] connected
03-19 09:39:31.051: I/System.out(4051): [CDS]close[40044]
03-19 09:39:32.732: I/System.out(4051): [CDS][DNS] getAllByNameImpl netId = 0
03-19 09:39:32.733: I/System.out(4051): [socket][22] connection /59.11.228.89:502;LocalPort=41867(10000)
03-19 09:39:32.733: I/System.out(4051): [CDS]connect[/59.11.228.89:502] tm:10
03-19 09:39:32.790: I/System.out(4051): [socket][/100.98.81.61:41867] connected
03-19 09:39:32.793: I/System.out(4051): [CDS]close[41867]
 
Upvote 0

alan1968

Active Member
Licensed User
Longtime User
in wifi DDM LOG
03-19 09:43:33.550: I/System.out(4051): [CDS][DNS] getAllByNameImpl netId = 0
03-19 09:43:33.551: I/System.out(4051): [socket][25] connection /7.11.228.89:502;LocalPort=58579(10000)
03-19 09:43:33.551: I/System.out(4051): [CDS]connect[/7.11.228.89:502] tm:10
03-19 09:43:43.554: I/System.out(4051): [socket][26:58579] exception
03-19 09:43:43.554: I/System.out(4051): [CDS]close[58579]
03-19 09:43:53.252: I/System.out(4051): [CDS][DNS] getAllByNameImpl netId = 0
03-19 09:43:53.252: I/System.out(4051): [socket][26] connection /109.11.228.89:502;LocalPort=41284(10000)
03-19 09:43:53.252: I/System.out(4051): [CDS]connect[/109.11.228.89:502] tm:10
03-19 09:44:03.254: I/System.out(4051): [socket][27:41284] exception
03-19 09:44:03.254: I/System.out(4051): [CDS]close[41284]

log B4A
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Connection Failed
(ErrnoException) android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
Connection Failed
(SocketTimeoutException) java.net.SocketTimeoutException: failed to connect to /84.11.228.89 (port 502) after 10000ms
Connection Failed
(SocketTimeoutException) java.net.SocketTimeoutException: failed to connect to /7.11.228.89 (port 502) after 10000ms
Connection Failed
(SocketTimeoutException) java.net.SocketTimeoutException: failed to connect to /109.11.228.89 (port 502) after 10000ms
 
Upvote 0

alan1968

Active Member
Licensed User
Longtime User
hi Erel,
Yes sometime ,i receve "failed" but is rare (once in ten +-) !? ,in wifi no problem ,vpn no problem but, the problem is only in 3G, if i connect to a ip or DDNS

B4X:
Sub so_Connected (Successful As Boolean)
    Dim s As ServerSocket
   Log("GetMyIP:"&s.GetMyIP)
   Log("GetMywifiIP:"&s.GetMywifiIP)
    If Successful Then
        Log("Connection Successful")
       
    Else
        Log("Connection Failed")
        Log(LastException)
    End If
    so.Close
End Sub



Sub ConnectButton_Click
   
    so.Initialize("so")
    so.Connect("81.11.228.89",502, 5000) 'no response to ping "ip bidon"
End Sub

3G:
03-21 18:18:39.359: I/B4A(27986): GetMyIP:100.70.196.23
03-21 18:18:39.360: I/B4A(27986): GetMywifiIP:127.0.0.1
03-21 18:18:39.360: I/B4A(27986): Connection Successful

03-21 18:18:38.816: I/System.out(27986): [CDS][DNS] getAllByNameImpl netId = 0
03-21 18:18:38.816: I/System.out(27986): [socket][27] connection /81.11.228.89:502;LocalPort=58027(5000)
03-21 18:18:38.816: I/System.out(27986): [CDS]connect[/81.11.228.89:502] tm:5
03-21 18:18:39.352: I/System.out(27986): [socket][/100.70.196.23:58027] connected
03-21 18:18:39.361: I/System.out(27986): [CDS]close[58027]

Wifi:

03-21 18:24:27.517: I/B4A(27986): GetMyIP:192.168.2.105
03-21 18:24:27.518: I/B4A(27986): GetMywifiIP:192.168.2.105
03-21 18:24:27.518: I/B4A(27986): Connection Failed
03-21 18:24:27.518: I/B4A(27986): (SocketTimeoutException) java.net.SocketTimeoutException: failed to connect to /81.11.228.89 (port 502) after 5000ms

03-21 18:24:22.511: I/System.out(27986): [CDS][DNS] getAllByNameImpl netId = 0
03-21 18:24:22.512: I/System.out(27986): [socket][29] connection /81.11.228.89:502;LocalPort=34315(5000)
03-21 18:24:22.512: I/System.out(27986): [CDS]connect[/81.11.228.89:502] tm:5
03-21 18:24:27.515: I/System.out(27986): [socket][30:34315] exception
03-21 18:24:27.515: I/System.out(27986): [CDS]close[34315]
 
Upvote 0

alan1968

Active Member
Licensed User
Longtime User
B4X:
Sub ConnectButton_Click
   
    so.Initialize("so")
    so.Connect("192.168.2.50",502, 5000) 'ip existe my plc in loca
End Sub

wifi
03-21 18:30:04.139: I/B4A(28875): GetMyIP:192.168.2.105
03-21 18:30:04.140: I/B4A(28875): GetMywifiIP:192.168.2.105
03-21 18:30:04.140: I/B4A(28875): Connection Successful

3G
03-21 18:32:47.984: I/System.out(28875): [CDS][DNS] getAllByNameImpl netId = 0
03-21 18:32:47.985: I/System.out(28875): [socket][2] connection /192.168.2.50:502;LocalPort=43956(5000)
03-21 18:32:47.986: I/System.out(28875): [CDS]connect[/192.168.2.50:502] tm:5
03-21 18:32:48.474: I/System.out(28875): [socket][/100.91.241.185:43956] connected
03-21 18:32:48.482: I/System.out(28875): [CDS]close[43956]
 
Upvote 0

M. Giray Ozkan

Member
Licensed User
Longtime User
by the way, there are many things that possibly go wrong. 3G connection stability, 3G network provider structure, tcp port availability, modem port forwarding issues etc...
 
Upvote 0
Top