QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The _CONNECTIONADDRESS function returns a connected user’s STRING IP address value.

Syntax

result$ = _CONNECTIONADDRESS](connectionHandle&)

Description

Example(s)

A Host logging new chat clients in a Chat program. See the _OPENHOST example for the rest of the code used.


f = FREEFILE
OPEN "ChatLog.dat" FOR APPEND AS #f ' code at start of host section before DO loop.

newclient = _OPENCONNECTION(host) ' receive any new client connection handles
IF newclient THEN
  numclients = numclients + 1 ' increment index
  Users(numclients) = newclient ' place handle into array
  IP$ = _CONNECTIONADDRESS(newclient)
  PRINT IP$ + " has joined." ' displayed to Host only
  PRINT #f, IP$, numclients ' print info to a log file
  PRINT #Users(numclients),"Welcome!" ' from Host to new clients only
END IF 

Explanation: The function returns the new client’s IP address to the IP$ variable. Prints the IP and the original login position to a log file. The information can later be used by the host for reference if necessary. The host could set up a ban list too.

See Also