PDA

View Full Version : using host_addr, hostip_toname, hostname_toip



dco045
28-01-2018, 22:50
Hi,

I'm looking to use host_addr and I receive a run time error popup

saying "HOST_ADDR" variable not defined or mispelled keyword

I guess I have to
uses "the good module"
But the help pages does not indicate the name of the needed module :cry:

I tried

uses "inet"
uses "lan"
without success.

Please . . . . .

Regards,


Dany

ErosOlmi
28-01-2018, 23:48
Check \SampleScripts\INet\INet_GetIPs.tBasic

ErosOlmi
29-01-2018, 00:14
Module is iNet
Your computer can have multiple network cards and cards can be activate/deactivated on the fly. For example if you connect to WiFi networks or you activate a VPN over a network.


Uses "inet"Uses "Console"


Long lCount


While %true
PrintL "Number of interfaces present:", INET_GetInterfaces
PrintL "------------------------------------------"

PrintL "-##-[IP ] [SubNet ] [Type]"
PrintL "------------------------------------------"
For lCount = 1 To INET_GetInterfaces
PrintL Format$(lCount, " 00"), _
Using$("\ \", INET_GetIp(lCount)), _
Using$("\ \", INET_GetSubNet(lCount)), _
Format$(INet_GetIpType(lCount), "0000")
Next

PrintL "------------------------------------------"
PrintL
PrintL " Press [ESC] to finish"
PrintL " 4 seconds for the next auto refresh "
PrintL " any key to refresh "
PrintL "------------------------------------------"
If WaitKey(4) = "[ESC]" Then Exit While
Cls
Wend

dco045
30-01-2018, 16:53
Hi Eros,

Your example works fine. But what about functions :


n = HOST_ADDR [(nIndex)]

s = HOSTIP_TONAME(nIP)

n = HOSTNAME_TOIP(sHost)

as they appear in online and offline Helpfiles ?

Regards,


Dany

ErosOlmi
31-01-2018, 00:15
If you press F1 while above a keyword you should get help about that keyword.
Help should say which module that keyword is inside.
The mentioned functions are inside TcpUdp module.
TcpUdp module implements some functionalities to create a Tcp or Udt server or use Tcp or Udp protocol to connect to a server that exposes some functionality over network.
There are some scripts inside \SampleScripts\TcpUdp\ directory that can show how to create a network communication using Tcp and Udp

Example on your mentioned functions:

uses "TcpUdp"uses "Console"


string sHost = "www.google.com"
Long nIp


nIp = HOSTNAME_TOIP(sHost) '---How your DNS resolve a host name
printl "HOSTNAME_TOIP of", sHost, "is", nIp
printl "IP_ToString is", IP_ToString(nIp) '---Translate Ip address into human one
printl "HOSTIP_TONAME is", HOSTIP_TONAME(nIp) '---How your DNS knows the ip
WaitKey

dco045
31-01-2018, 13:10
If you press F1 while above a keyword you should get help about that keyword.
Help should say which module that keyword is inside.
The mentioned functions are inside TcpUdp module.
TcpUdp module implements some functionalities to create a Tcp or Udt server or use Tcp or Udp protocol to connect to a server that exposes some functionality over network.
There are some scripts inside \SampleScripts\TcpUdp\ directory that can show how to create a network communication using Tcp and Udp

Example on your mentioned functions:

uses "TcpUdp"uses "Console"


string sHost = "www.google.com"
Long nIp


nIp = HOSTNAME_TOIP(sHost) '---How your DNS resolve a host name
printl "HOSTNAME_TOIP of", sHost, "is", nIp
printl "IP_ToString is", IP_ToString(nIp) '---Translate Ip address into human one
printl "HOSTIP_TONAME is", HOSTIP_TONAME(nIp) '---How your DNS knows the ip
WaitKey




HI Eros,
But the reason I posted on these function is that the relevant


uses "tcpudp"

doesn't appear in help files either online or offline.

As I said in my PM of 21 january, I begin using ThinBasic and I make huge use of help files, and before disturbing TB developpers , be sure that, I try, try, press F1, read help, look in SamplesScripts. My F1 key is completely worn out. :mad: :mad: :mad: :violent:
So for this precise case, help files may be completed. :)


Regards,



Dany

ErosOlmi
01-02-2018, 23:03
Strange :confused:

What thinBasic version are you using?
You can check thinBasic verion inside thinAir/Help menu/About thinAIr/

Please check here for online but you should also see in offline, both are generated from the same source:
http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?tcpudp.htm
http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?host_addr.htm
http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?hostname_toip.htm

Yes, help is not so much exhaustive ... I admit, but should be there.

Latest thinBasic version is 1.10.4.0: http://www.thinbasic.com/community/showthread.php?12778-thinBasic-1-10-x
It is Beta but quite stable

dco045
03-02-2018, 00:33
Strange :confused:

What thinBasic version are you using?
You can check thinBasic verion inside thinAir/Help menu/About thinAIr/

Please check here for online but you should also see in offline, both are generated from the same source:
http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?tcpudp.htm
http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?host_addr.htm
http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?hostname_toip.htm

Yes, help is not so much exhaustive ... I admit, but should be there.

Latest thinBasic version is 1.10.4.0: http://www.thinbasic.com/community/showthread.php?12778-thinBasic-1-10-x
It is Beta but quite stable

Hi Eros.

Version 1.9.16.17 . I only downloaded 1.10 on a sandbox PC. I am prudent with versions labelled as Beta. But if you say 'quite stable ' ? I'll try it.

The problem comes because I was looking for Hex$() syntax, using either online(web) or offline help.
Using index view, I then saw host_addr, hostip_toname and hostname_toip functions, I remembered a tool I had on Unix. I wanted to try, but by this way, we do not know the necessary ' uses "module " '.
That's why I asked that question. Maybe it's worth remembering the "uses" in the pages of these functions.


As we say in France : "ça va sans dire, mais ça va mieux en le disant" , "It goes without saying, but it's better by saying it", "Inutile dire, ma è meglio dirlo" :cool:


Best regards,



Dany

ErosOlmi
07-02-2018, 13:39
As you well know :D writing documentation is one of the hardest part in a project.
Also writing documentation is something you learn, sometimes from others having more experience.
thinBasic Help material is my only experience in writing documentation and I missed suggestions from professionals.
So I'm here to absorb indications and do better.

The idea that I've followed is:

I've structured all thinBasic modules in a tree under "thinBasic modules" http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?thinbasic_modules.htm
In this page is described what are thinBasic modules and how to use them
Then every module has a module home page that indicates how to use that specific module: http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?tcpudp.htm
under module home page, all features inside that module are dependent to the fact that you need to load that module in your script using: USES "module name"


I have to admit it is not so clear and immediate to understand.

Now ... what to change in order to make module/keywords/features dependency without the need to change all thinBasic keywords?

9809

Petr Schreiber
07-02-2018, 22:11
Hi Eros, Dany,

my experience with documentation is that no matter how good it is, people prefer to not read it a all and jump to action first. That does not mean there is no point to do documentation, but that the guidance of the user can be approached differently for some cases.

So what about the following hint for the programmer - when thinBASIC finds unknown keyword ( error 30 ) or Variable not defined or misspelled Keyword ( error 18 ), thinBasic could take the token found and try to find it in all installed modules, hinting the user.

To give example:


uses "Console"

print strformat$("45 degress to radians is {1}", DegToRad(45))

waitkey


This now reports "Variable not defined or misspelled Keyword" for token "DegToRad".
With my suggestion, thinBASIC would lookup tokens defined in all installed modules and as a result give hint:
"Consider adding Uses "Math" to your script"

I think it would be perfectly okay to have the module token list done statically (file generated during thinBASIC installation creation).


Petr

ErosOlmi
07-02-2018, 23:23
Great idea Petr.

I will see how to generate a static file to be distributed with thinBasic in order to quickly find keywords/equates/UDT and in which modules are defined.
If runtime error occurs and script is not obfuscated/bundled, I will first check in that file and suggest possible module.

Petr Schreiber
08-02-2018, 21:37
Hi Eros,

I created proof of concept of keyword lister here:
http://www.thinbasic.com/community/showthread.php?12840-Keywords-constants-UDTs-and-classes-for-each-module&p=94133#post94133


Petr

dco045
09-02-2018, 00:28
Hi Eros and Petr,

When I asked for module to use for these functions, I could not imagine that it would cause such an avalanch of ideas...... :comp1:

I can only say that Petr's idea is very good.:yahoo:
Although I do not quite agree with him when he says "people prefer to not read it and jump to action first". ;--)

Best regards



Dany

Petr Schreiber
09-02-2018, 08:57
Hi Dany,

it was a bit exaggerated generalization, yet I found it true in notable amount of cases, when counting my interactions outside TB world. ThinBasic community is lucky to have so many members which do not fall into this category :) Thank you for it.


Petr