Returns a port address used for a local or remotely-connected socket handle.
[ lPort = ] WsGetPort ( socket [, bLocal ] )
The WsGetPort procedure syntax has the following parts:
Name |
Type |
Description |
lPort |
Long |
The local or remote host's port address. |
socket |
Val ASocket |
A descriptor identifying a local or remotely-connected socket. |
bLocal |
Val Bool |
If True, returns a local port address. If False, returns a remotely-connected port address. The default value is True. |
If bLocal is set to True, the WsGetPort function retrieves the port address of the local socket, for example, a datagram socket or a connected socket. If bLocal is set to False, the WsGetPort function retrieves the port address of the remotely-connected socket only. The WsGetPort function will return -1 if it is unable to retrieve anything.
The following example will return the remote port for the specified remote host for the socket handle:
! Open a socket:
lSocket1=WsCreate(aWsTcpIp,0)
! Associate a local host with a socket at a local port:
WsBind(lSocket1,lPort,lHost)
! Set the Socket to listen for an incoming connection from a client:
WsListen(lSocket1)
! Attempts to return a readwrite socket to the remote client in twenty seconds:
socket2=WsAccept(lsocket1,20000)
! Get the remote host address:
lRemotePort=WsGetPort(socket2, False)