MasterScan
Lab_Matlab_control Master Branch
|
An abstract interface for working with sockets.
dotsAllSocketObjects defines a standard interface for working with network sockets in Snow Dots. Subclasses of dotsAllSocketObjects are expected to implement a set methods that accomplish socket behaviors. These may be wrappers around mex function calls, for example.
The purpose of the dotsAllSocketObjects interface is to allow Snow Dots to run on any Matlab platform that has a native sockets implementation. Each dotsAllSocketObjects subclass must encapsulate the details of the sockets implementation.
Depending on how socket behaviors are implemented, a subclass may need to define properties, or it may store data with a mex function or elsewhere. Thus, properties are not expected as part of the dotsAllSocketObjects interface.
Any Snow Dots function that wants to use network sockets should create an instance of a dotsAllSocketObjects class that is appropriate for the local machine. The machine-appropriate class should be specified in dotsTheMachineConfiguration, as the default "socketClassName". This value can be accessed through dotsTheMachineConfiguration. For example:
Properties and Events | |
null | id = open(self, localIP, localPort, remoteIP, remotePort) |
Open a new socket and return an identifier for it. More... | |
null | status = close(self, id) |
Close an open socket. More... | |
null | hasData = check(self, id, timeoutSecs) |
Check whether a socket has a packet to read. More... | |
null | data = readBytes(self, id) |
Read byte data from a socket. More... | |
null id = open(self, localIP, localPort, remoteIP, remotePort) |
Open a new socket and return an identifier for it.
localIP | string IP address to bind on this host |
localPort | port number to bind on this host |
remoteIP | string IP address to connect to |
remotePort | port number to connect to |
Must open an new socket to communicate between the host at localIP:localPort and remoteIP:remotePort.
Must return a nonnegative scalar identifier for the new socket, or a negative scalar to indicate an error.
null status = close(self, id) |
Close an open socket.
Write byte data to a socket.
Close all open sockets.
id | a socket identifier as returned from open() |
Must close a previosuly opened socket and free resources as needed.
Must return a nonnegative scalar, or a negative scalar to indicate an error.
Must close all sockets that were opened with open() and free all socket resources.
Must return a nonnegative scalar, or a negative scalar to indicate an error.
id | a socket identifier as returned from open() |
data | an array of data to send |
Must send data from the @id socket to its connected remote host. data might have any type, but should be treated here as an array of uint8 (single bytes).
For UDP sockets, write() should write the contents of data to a single packet and send it immediately.
Must return a nonnegative scalar, or a negative scalar to indicate an error. Must not block.
null hasData = check(self, id, timeoutSecs) |
Check whether a socket has a packet to read.
id | a socket identifier as returned from open() |
timeoutSecs | optional time to wait for a packet |
Must return true if the id socket has a data ready to read, or false if it has none. if timeoutSecs is provided, may block, waiting for a packet for that many seconds. Otherwise, must not block.
check() must leave any available packet in place, to be consumed during the next read().
null data = readBytes(self, id) |
Read byte data from a socket.
id | a socket identifier as returned from open() |
Must read, consume, and return data available at the @id socket. The data might have had any type initially, but should be treated here as an array of uint8 (single bytes).
For UDP sockets, readBytes() should consume one available packet buffered at the socket.
If the socket has no data, readBytes() shoud return an empty array immediately. Must not block.