Avisaro Online Documentation - Wiki
Impressum Kontakt Sitemap

BIND

Description

The BIND command can be used to bind a TCP or UDP socket to a specific network interface or to remove binding. Binding only works if more than one network interfaces are enabled. Also, a socket must be allocated (by any means) for BIND to work. Binding creates a relationship between a socket and a physical network interface. In some cases binding happens implicitely. These are:

  • An unbound listening TCP socket that receives a SYN is bound to the network interface where the SYN arrives.
  • An unbound connecting TCP socket that receives an ACK is bound to the network interface where the ACK arrives.

If BIND was never used on a socket, that socket is unbound by default which means that:

  • Unbound listening TCP sockets listen on all available network interfaces.
  • Unbound connecting TCP sockets transmit SYNs over all available network interfaces.
  • Unbound UDP sockets transmit and receive simultaneously over all available network interfaces.

BIND has the following consequences if used on a socket:

  • If a TCP socket is bound before it goes into listen or connecting state, those socket ony accepts connections (or send SYNs) to the network interface where it is bound to.
  • Bound UDP sockets only transmit over their bound interface.
  • Bound UDP sockets only receive packets from their bound interface.

A bounded socket reverts to "unbound" state if one of these events occur:

  • The socket is closed.
  • The BIND command is executed with NONE as argument.
  • A BASIC script executes the "bind" instruction with -1 as argument.

Arguments

BIND requires two arguments. The first one is the socket handle, which specifies either a UDP or TCP socket. The second one is one of the words WLAN, ETH or NONE. If WLAN is given, the socket is bound to the WLAN interface. ETH binds it to the Ethernet interface, and NONE unbounds the socket so it can be used by both interfaces.

Return Value

ERR_ARGUMENT if an argument was wrong.
ERR_NOT_OPEN if the socket is not allocated.
ERR_REJECTED if less than two network interfaces are enabled.
ERR_OK if everything works well.

Example

BIND 101 WLAN

Binds socket handle 101 to the WLAN interface

Remarks

BIND only makes sense on modules with more than one network interfaces.