Android Question Socket connection fail

Madhav Tenneti

Member
Licensed User
Longtime User
When I Enter the parameters required for ...

socket1.connect("10.0.1.125", 8080, 2000) The Socket_connected event is firimg, I know this as I have a Msgbox popup on sucessful connection.

However when I use variables in place of values as given below...

socket1.connect(IP, Portval, Tmout)

the socket_connected event fails, i receive no Msgbox popup.

The values IP, Portval are retrieved from a file stored as given here in a csv file...

Code in Activity create...

If File.Exists(File.DirInternal, "Config.csv") = True Then
Readconf.Extract
Socket1.Connect(IP,portval,tmout)
Else
pnlSettings.Visible = True
pnlControls.Visible = False
pnlHelp.Visible = False
End If

Readconf is a code module....

'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim sf As StringFunctions
Dim Readdata, chartest As String
Dim portvaltxt As String
Dim sbb As StringBuilder
Dim strlen, charpos, fieldstrt As Byte
End Sub

Sub Extract
sbb.Initialize
sf.Initialize
Readdata = File.ReadString(File.DirInternal, "Config.csv")
'Msgbox(Readdata, "The Current config")
strlen = sf.Len(Readdata)
For charpos = 1 To strlen
chartest = sf.Mid(Readdata, charpos, 1)
If chartest <> "," Then
sbb.Append(chartest)
Else
Exit
End If
Next
Main.ip = sbb
fieldstrt = charpos+ 1
portvaltxt = sf.Mid(Readdata, fieldstrt, (strlen-charpos))
Main.Portval = sf.Val(portvaltxt)
End

Using Msgbox have verified that the IP has a value as set in the file "config.csv" & the portval has a value too as extracted from "config.csv". Tmout = 2000 was initialized in the Process globals.

Why then is the Socket1_Connected failing when variables are passed, well actually this code was working with earlier versions of B4A, cant remember when this problem came up, frankly my working code was from early 2016.

Any quick update will be a great help.

Thanks in advance
 

Madhav Tenneti

Member
Licensed User
Longtime User

Thanks Erel,

You were right, the IP was taking an extra white space, wasn't clear with messagebox. Sorry will use the Code Tags to put in the Code hereafter.

Thank you once again for prompt support, I am building a home automation software with voice recognition, every thing working fine except for the socket IP and Port setting, now that too is resolved.

Had published a very preliminary App to just understand VR on the Google App store last year, had hard coded the IP, port & Timeout then, now added improved features, settings & vocabulary help with pronunciation, will publish in a day or two.

My app on Google play store is VRXBeeHA. (will be upgrading it now) the earlier App was to understand the process of Publishing the App on the Playstore.



Regards

Madhav Tenneti
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…