Returns the address for a specified local or remotely-connected socket handle.
[ vReturn = ] WsGetAddress ( socket [, bLocal ] )
The WsGetAddress procedure syntax has the following parts:
Name |
Type |
Description |
vReturn |
Variant |
If no error occurs, WsGetAddress returns the Internet address of a local socket or a remotely-connected host. If the socket is not valid or not connected, returns -1. Address could be Long (for IPv4) or (ATEasy 2024) array of 16 bytes (for IPv6 socket). |
socket |
Val ASocket |
A descriptor identifying a local or remotely-connected socket. |
bLocal |
Val Bool |
If True, returns a local socket address. If False, returns a remotely-connected host address. The default value is True. |
If bLocal is set to True, the WsGetAddress function retrieves the address of the local socket, for example, a datagram socket or a connected socket. If bLocal is set to False, the WsGetAddress function retrieves the address of the remotely-connected socket only. The WsGetAddress function will return -1 if it is unable to retrieve anything.
Note: Calling WsGetAddress(socket) is the same as calling GetNameAddress(WsGetName (socket)).
The following example will return the address for the specified remote host for the socket handle:
!Open a socket
socket1=WsCreate(aWsTcpIp,0)
!associate a local host with a socket at a local port
WsBind(socket1,lPort,lHost)
! Set the Socket to listen for an incoming connection from a client:
WsListen(socket1)
!attempts to return a readwrite socket to the remote client in twenty seconds:
socket2=WsAccept(socket1,20000)
!Get the remote host address
lRemoteHost=WsGetAddress(socket2, False)
WsBind, WsClose, WsConnect, WsCreate, WsGetAddressName, WsGetName, WsGetNameAddress