hb_inetGetHosts()

HB_INETGETHOSTS()

Get an array of IP addresses of a host

Syntax

      HB_INETGETHOSTS( <cName> ) -> aHosts

Arguments

<cName>

Returns

An array of IP addresses

Description

Returns an array containing all the IP addresses associated with a given host name. The IP addressess returned by this funtion are strings in quad dot notations, eg “192.168.1.1”, and can be directly used into hb_InetConnectIP().

cName can be any string: valid DNS names (eg. “www.myserver.com”), locally available names (e.g. “localhost” or windows Network Neighborhood names), or even IP addresses in quad dot notation.

NOTE: This function is not thread safe (by design), and programmers must be sure not to use it at the same time in two different threads, or not to use it together with a hb_InetConnect(). If this kind of situation should ever arise, you are advised to use a thread MUTEX.

On error, and if the server can’t be found, the function returns NIL.

Compliance

Harbour

hb_inetConnect()

HB_INETCONNECT()

Connect a socket to a remote server by IP address or name

Syntax

      HB_INETCONNECT( <cAddress>, <nPort> ) -> SOCKET

      HB_INETCONNECT( <cAddress>, <nPort>, <socket> ) -> NIL

Arguments

<cAddress>

<nPort>

<socket>

Returns

(First form) INET socket

(Second form has no return value)

Description

Connects to a remote server described by cAddress, that can be in quad dot notation (e.g. “192.168.1.1”) or in DNS name (e.g. “www.xharbour.org”), using the desired port.

hb_InetConnect uses “gethostbyname” C system call to find the network address of the specified server; this means that this call is an hybrid function doing both a DNS scan and a TCP/IP connection. hb_InetConnect is not thread safe, and the program must take care that two hb_InetConnect functions are never called at the same moment from two different threads (or that hb_InetGetHosts is not called in the same moment as an hb_InetConnect).

The second version of this function accepts a pre-built socket as a parameter. This allows to kill asyncronously a thread waiting for hb_InetConnect to connect, and then cleaning up the leftover socket data. Also, it is possible to give timeout to the given SOCKET, but this timeout will be used only in the connection phase, after that the network address resolution is completed. Use GetHosts() and hb_InetConnectIP for a finer timeout control. On error, the error of the returned socket is set. The error could be due to unavailable name resolving service, host name not valid, host address not reachable and host reachable but port not open.

Compliance

Harbour