[Home] [Downloads] [Search] [Help/forum]


Script function


Read about scripting




Find a free port for UDP listening


long GetUdpPort(long First, long Last);

View list of data type meanings


This function finds a free port for use by MUSHclient as a UDP listener. It operates by scanning all open worlds for ports in use by UdpListen. It then works through the range you specify to find one that is not in use.

However this test is only for port used by MUSHclient. There is no guarantee that the port is not in use by another application.

The intention is for plugin writers to use it to find a port in a range (say, 4000 to 4100) which is not in use by another plugin, or the same plugin in another world.

The First and Last arguments are port numbers, inclusive, that you wish to be scanned. eg. GetUdpPort (4000, 4100) would find a port in the range 4000 to 4100 inclusive.

The port numbers must be greater than zero and less than 65535. Also the last port number must be greater than or equal to the first port number.

Available in MUSHclient version 3.66 onwards.

VBscript example

Note GetUdpPort (4000, 4100)

Jscript example

Note (GetUdpPort (4000, 4100))

Lua example

free_port = GetUdpPort (4000, 4100)

Return value

0 : No free port was found in the specified range, or the range was invalid.

non-zero : A port not in use by MUSHclient's UdpListen function.

See Also ...


(UdpListen) Listens for incoming packets using the UDP protocol
(UdpPortList) Returns an array of all the UDP ports in use by this world
(UdpSend) Sends a packet over the network using the UDP protocol

(Help topic: function=GetUdpPort)

Documentation contents page

Search ...

Enter a search string to find matching documentation.

Search for:   

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]