Opticka 2.16.1
Opticka is an experiment manager for behavioral research.
Loading...
Searching...
No Matches
dataConnection Class Reference

dataConnection Connects and manages a socket connection More...

Detailed Description

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:

  • close() closes connection
  • checkData() check if there is data sent from remote object available to read
  • checkClient() if you are a TCP server, check if a client tries to connect
  • readVar() & writeVar() reads structures and objects over the wire There is also an autoServer mode, where the object opens a TCP server and responds to commands, allowing you to send data and EVAL commands on a remote machine...

Copyright ©2014-2023 Ian Max Andolina — released: LGPL3, see LICENCE.md

Inheritance diagram for dataConnection:

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
 

Constructor & Destructor Documentation

◆ dataConnection()

function dataConnection::dataConnection ( in  varargin)

CONSTRUCTOR.

Configures input structure to assign properties

Member Function Documentation

◆ checkClient()

function dataConnection::checkClient ( in  me)

Check client.

Check status

◆ checkData()

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

Returns
hasData (logical)

◆ checkStatus()

function dataConnection::checkStatus ( in  me,
in  conn 
)

Check status.

Check status

◆ close()

function dataConnection::close ( in  me,
in  type,
in  force 
)

Close the connection.

Close the ethernet connection

◆ closeAll()

function dataConnection::closeAll ( in  me)

Close all connections.

Close all connections

◆ echoServer()

function dataConnection::echoServer ( in  me)

echo server

Run the server loop

◆ flush()

function dataConnection::flush ( in  me)

Close all connections.

Close all connections

◆ loadobj()

static function dataConnection::loadobj ( in  in)
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.

◆ open()

function dataConnection::open ( in  me)

Open an ethernet connection.

Open an ethernet connection, dependent on whether we are using a UDP or TCP connection

◆ read()

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.

Parameters
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
Returns
data the data returned from the connection

◆ readline()

function dataConnection::readline ( in  me)

Read a single line of data.

Read a single line of data from the connection

Returns
data read from connection

◆ readLines()

function dataConnection::readLines ( in  me,
in  N,
in  order 
)

read last N lines

Flush the server messagelist

◆ readVar()

function dataConnection::readVar ( in  me)

Read any available variable from the given pnet socket.

Read any avalable variable from the given pnet socket.

◆ sendCommand()

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'

Parameters
varargincan be

◆ startServer()

function dataConnection::startServer ( in  me)

Initialize the server loop.

Initialize the server loop

◆ write()

function dataConnection::write ( in  me,
in  data,
in  formatted,
in  sendPacket 
)

Write data to the given pnet socket.

Parameters
datato 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

◆ writeVar()

function dataConnection::writeVar ( in  me,
in  varargin 
)

Member Data Documentation

◆ autoOpen

Property dataConnection::autoOpen

do we try to open the connection on construction

◆ autoServer

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'

◆ cleanup

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!!!

◆ dataOut

Property dataConnection::dataOut

the data to send to the remote object

◆ dataType

Property dataConnection::dataType

the format the data is required

◆ lAddress

Property dataConnection::lAddress

the local address to open

◆ lPort

Property dataConnection::lPort

the local port to open

◆ protocol

Property dataConnection::protocol

protocol = 'tcp' | 'udp'

◆ rAddress

Property dataConnection::rAddress

the remote address to open

◆ readSize

Property dataConnection::readSize

default size of chunk to read for tcp

◆ readTimeOut

Property dataConnection::readTimeOut

default read timeout

◆ rPort

Property dataConnection::rPort

the remote port to open

◆ type

Property dataConnection::type

Whether this object is a 'client' or 'server' (TCP). Normally UDP objects are always clients

◆ verbosity

Property dataConnection::verbosity

do we log to the command window?

◆ writeTimeOut

Property dataConnection::writeTimeOut

default write timeout


The documentation for this class was generated from the following file: