SocketServerManager\Register

Description Register a station with a group.
Returns Invalid when complete
Usage Script
Function Groups Stream and Socket
Format \SocketServerManager\Register(Context, StationKey, GroupName[, IPAllowString])
Parameters  
Context
Required. The context should be the root tag. This must include Discriminator() and Context() subroutines.
StationKey
Returned by Discriminator() in the root tag. A unique string that has meaning only VTScada, used to identify a particular station.
GroupName
The name of an IPListener tag (or group). This will be the source of the new data streams.
IPAllowString
An optional string. If valid, inbound connections will be restricted as specified. May be a partially specified address to allow a range of connection IP addresses. The string is one or more semicolon delimited IP addresses (or address ranges)
Comments Public subroutine used by modules that are to receive inbound connections. This is intended for, but not limited to, VTScada driver tags.

Users should wait until \SocketServerManager\Started is true before attempting to use the Register or Unregister functions.

GroupName defines a group containing driver tags and server socket tags. Typically the name of an IP Network Listener. Groups are  for use by advanced VTScada programmers, allowing them to associate multiple IP Network Listeners.

Context provides the context for the discriminator calls. The StationKey must be unique within the StationList of a GroupNode\DiscrimNode.

The Station context must have Discriminator() and Connect() callbacks. The Discriminator module takes a sample of incoming data and returns a station key if it can understand the protocol. The Connect module will be called on the exact station context as indicated by the station key. Connect must return (a) the workstation name of the station server and (b) the object  value of a context implementing an ExternalSocketConnect callback. This was  intended for, but is not limited to, TCP/IP and UDP/IP port tags.

The service will not Connect() to a station unless the IP address of the remote stream passes an optional IPAllowString filter check. Utility functions ArrayToString() and StringToArray are provided in the SocketServerManager to ensure that the addresses are provided in the correct format, but in general, you can rely on the result returned from a pIPAddressList() widget, used in the tag configuration.

A station must be UnRegistered when about to change the StationKey or GroupName. The IPAllowString can be updated by calling register again.

Example:

[
  ActiveDevAddr  {PLC address to use in reads & writes                    };
  ListenerGroup  {SocketServerManager group to join                       };
IPAddressAllow { Semicolon delimited string of IP addresses (or ranges
                        which can connect to this station }; ] Init [
  If Valid(Name) && \SocketServerManager\Started && Watch(1, ActiveDevAddr, ListenerGroup, IPAddressAllow);
  [
    CriticalSection(
      IfThen(Valid(ActiveDevAddr) != Valid(RegDevAddr) || ActiveDevAddr != RegDevAddr ||
             Valid(ListenerGroup) != Valid(RegGroup)   ||    ListenerGroup != RegGroup,
        \SocketServerManager\Unregister(Root, RegDevAddr, RegGroup);
      );
      RegDevAddr = ActiveDevAddr;
      RegGroup   = ListenerGroup;

       { Register with SocketServerManager }
      \SocketServerManager\Register(Root, RegDevAddr, RegGroup, IPAddressAllow);
    );
  ] ]