![]() |
Opticka 2.16.1
Opticka is an experiment manager for behavioral research.
|
dataConnection Connects and manages a socket connection More...
dataConnection Connects and manages a socket connection
Connects and manages TCP/UDP Communication. We allow both TCP and UDP connections, and can choose to be a client or server in TCP mode. To use at its simplest in UDP mode, both clients on the same machine:
OPEN CLIENT 1
d1=dataConnection('rPort',4321,'lPort',1234,'protocol','udp','autoOpen',1)
OPEN CLIENT 2
d2=dataConnection('rPort',1234,'lPort',4321,'protocol','udp','autoOpen',1) d1.write('my command') data = d2.read() d2.write('my response') response = d1.read() d1.close(); d2.close();
Please read through the other public methods:
Copyright ©2014-2023 Ian Max Andolina — released: LGPL3, see LICENCE.md
Public Member Functions | |
| function | dataConnection (in varargin) |
| CONSTRUCTOR. | |
| function | open (in me) |
| Open an ethernet connection. | |
| function | close (in me, in type, in force) |
| Close the connection. | |
| function | closeAll (in me) |
| Close all connections. | |
| function | checkData (in me) |
| Check if there is data non-destructively. | |
| function | flush (in me) |
| Close all connections. | |
| function | readline (in me) |
| Read a single line of data. | |
| function | readLines (in me, in N, in order) |
| read last N lines | |
| function | read (in me, in all, in dataType, in size) |
| Read any avalable data from the given pnet socket. | |
| function | write (in me, in data, in formatted, in sendPacket) |
| Write data to the given pnet socket. | |
| function | readVar (in me) |
| Read any available variable from the given pnet socket. | |
| function | writeVar (in me, in varargin) |
| function | checkClient (in me) |
| Check client. | |
| function | checkStatus (in me, in conn) |
| Check status. | |
| function | startServer (in me) |
| Initialize the server loop. | |
| function | sendCommand (in me, in varargin) |
| Send command to a remote dataConnection server. | |
| function | echoServer (in me) |
| echo server | |
Static Public Member Functions | |
| static function | loadobj (in in) |
| load object method | |
Public Attributes | |
| Property | type |
| Property | protocol |
| protocol = 'tcp' | 'udp' | |
| Property | lPort |
| the local port to open | |
| Property | rPort |
| the remote port to open | |
| Property | lAddress |
| the local address to open | |
| Property | rAddress |
| the remote address to open | |
| Property | autoOpen |
| do we try to open the connection on construction | |
| Property | dataOut |
| the data to send to the remote object | |
| Property | dataType |
| the format the data is required | |
| Property | verbosity |
| do we log to the command window? | |
| Property | autoServer |
| Property | readTimeOut |
| default read timeout | |
| Property | writeTimeOut |
| default write timeout | |
| Property | readSize |
| default size of chunk to read for tcp | |
| Property | cleanup |
| function dataConnection::dataConnection | ( | in | varargin | ) |
CONSTRUCTOR.
Configures input structure to assign properties
| function dataConnection::checkClient | ( | in | me | ) |
Check client.
Check status
| function dataConnection::checkData | ( | in | me | ) |
Check if there is data non-destructively.
Check if there is data non-destructively, i.e. attempt to read from the given pnet socket without consuming available data
| function dataConnection::checkStatus | ( | in | me, |
| in | conn | ||
| ) |
Check status.
Check status
| function dataConnection::close | ( | in | me, |
| in | type, | ||
| in | force | ||
| ) |
Close the connection.
Close the ethernet connection
| function dataConnection::closeAll | ( | in | me | ) |
Close all connections.
Close all connections
| function dataConnection::echoServer | ( | in | me | ) |
echo server
Run the server loop
| function dataConnection::flush | ( | in | me | ) |
Close all connections.
Close all connections
|
static |
load object method
we have to make sure we don't load a saved object with connection numbers intact, this can cause wrongly closed connections if another dataConnection is open with the same numbered connection. cleanup property is used to stop the delete method from calling close methods.
| function dataConnection::open | ( | in | me | ) |
Open an ethernet connection.
Open an ethernet connection, dependent on whether we are using a UDP or TCP connection
| function dataConnection::read | ( | in | me, |
| in | all, | ||
| in | dataType, | ||
| in | size | ||
| ) |
Read any avalable data from the given pnet socket.
Read any avalable data from the given pnet socket.
| all | (optional, logical) whether to read as much data as is present or only one item |
| (optional) | dataType the type of data to read in |
| (optional) | size is size in bytes to read |
| function dataConnection::readline | ( | in | me | ) |
Read a single line of data.
Read a single line of data from the connection
| function dataConnection::readLines | ( | in | me, |
| in | N, | ||
| in | order | ||
| ) |
read last N lines
Flush the server messagelist
| function dataConnection::readVar | ( | in | me | ) |
Read any available variable from the given pnet socket.
Read any avalable variable from the given pnet socket.
| function dataConnection::sendCommand | ( | in | me, |
| in | varargin | ||
| ) |
Send command to a remote dataConnection server.
Send command to remote dataConnection server. Commands can be 'echo', 'put', 'get' and 'eval'
| varargin | can be |
| function dataConnection::startServer | ( | in | me | ) |
Initialize the server loop.
Initialize the server loop
| function dataConnection::write | ( | in | me, |
| in | data, | ||
| in | formatted, | ||
| in | sendPacket | ||
| ) |
Write data to the given pnet socket.
| data | to write to connection |
| formatted | (0[default]|1) whether to send data raw (0) or as a formatted string (1) |
| sendPacket | (0|1[default]) for UDP connections actually send the packet or wait to fill buffer with another call first |
| function dataConnection::writeVar | ( | in | me, |
| in | varargin | ||
| ) |
| Property dataConnection::autoOpen |
do we try to open the connection on construction
| Property dataConnection::autoServer |
this is a mode where the object sits in a loop and can be controlled by a remote matlab instance, which passes commands the server can 'put' or 'eval'
| Property dataConnection::cleanup |
sometimes we shouldn't cleanup connections on delete, e.g. when we pass this object to another matlab instance as we will close the wrong connections!!!
| Property dataConnection::dataOut |
the data to send to the remote object
| Property dataConnection::dataType |
the format the data is required
| Property dataConnection::lAddress |
the local address to open
| Property dataConnection::lPort |
the local port to open
| Property dataConnection::protocol |
protocol = 'tcp' | 'udp'
| Property dataConnection::rAddress |
the remote address to open
| Property dataConnection::readSize |
default size of chunk to read for tcp
| Property dataConnection::readTimeOut |
default read timeout
| Property dataConnection::rPort |
the remote port to open
| Property dataConnection::type |
Whether this object is a 'client' or 'server' (TCP). Normally UDP objects are always clients
| Property dataConnection::verbosity |
do we log to the command window?
| Property dataConnection::writeTimeOut |
default write timeout