|Top Previous Next|
TiOS supports up to 16 sockets, but there may be platforms with less than 16 sockets available. You can obtain the number of sockets available for your platform using the sock.numofsock property.
Since there can be multiple sockets, you must state which socket are you referring to when changing properties or invoking methods. This is done using the sock.num property. For example:
Can you tell what socket the statement above applies to? Neither can the platform. Thus, the correct syntax would be:
Now the platform knows which socket you're working with. Once you have set the socket selector (using sock.num), every socket-specific method and property after that point is taken to refer to that socket. Thus:
The events for this object are not separate for each socket. An event such as on_sock_data_arrival serves all sockets on your platform. Thus, when an event handler for the socket object is entered, the socket selector is automatically switched to the socket number on which the event occurred:
As a result of this automatic switching, when an event handler for a socket event terminates, the sock.num property retains its new value (nothing changes it back). You must take this into account when processing other event handlers which make use of a socket (and are not socket events). In other words, you should explicitly set the sock.num property whenever entering such an event handler, because the property might have been automatically changed prior to this event. To illustrate:
To recap, only one of two things may change the current sock.num: (1) manual change or (2) a socket event. You cannot assume the number has remained unchanged if you set it somewhere else (because a socket event might have happened since).