tcpclient

Create a TCP Client.

Attention: Available only with Twin Activate commercial edition.

Syntax

cobj = tcpclient(address,port)

cobj = tcpclient(address,port,[Name, value])

Inputs

address
server address tag
Type: string
port
Numeric port number to connect to.
Type: scalar
Name, value
Name
Type: string
Valid options are:
Name
Value
Timeout
Numeric value in seconds, time given for read operation to finish. Negative value to wait forever.
Type: double
UserData
User data to store in client object.
Type: scalar | vector | matrix | struct | cell | Boolean | string
ByteOrder
Valid values are 'network' and 'host' (default).
Type: string

Outputs

cobj
TCPIP client object.
Type: TCP client
property, values
Type: string
Valid options are:
Property Name
Description/Values
UserData
User data.
Type: scalar | vector | matrix | struct | cell | Boolean | string
ByteOrder
Byte order used for read/write.Valid values are 'network' and 'host' (default).
Type: string
Timeout
Numeric value in seconds, time given for read operation to finish. Negative value to wait forever.
Type: double
ClientSock
Client socket. Readonly property.
Type: scalar
Name
Name of the client object. Readonly property.
Type: string
Type
Value is 'tcpclient'. Readonly property.
Type: string
Port
Server port number.Readonly property.
Type: scalar
Address
Server ip address.Readonly property.
Type: string
Status
Connection status.Readonly property.
Type: string
NumBytesAvailable
Number of bytes available to read. Readonly property.
Type: scalar
NumBytesWritten
Number of bytes written by write function call. Readonly property.
Type: scalar
Terminator
Termination caharacter used read/write string data. Readonly property.
Type: scalar | string
WriteDataType
Data type used to write data. Readonly property.
Type: string
ReadDataType
Data type used to read data. Readonly property.
Type: string
Function Name, Syntax
Type: string
Valid options are:
Function Name
Description/Syntax/Arguments
read
reads data.
data=read() data=read(NumberOfBytes) data=read(NumberOfBytes,DataType) NumberOfBytes is a scalar. Supported "DataType" values are 'string', 'double' ,'int8','int16','int32','int64','uint8','uint16','uint32','uint64'.
write
writes data.
data=write(Data) data=write(Data, DataType) Supported type for "Data" is string, real number, real matrix. Supported "DataType" values are 'string', 'double' ,'int8','int16','int32','int64','uint8','uint16','uint32','uint64'.
close
Closes connection.

Examples

Connecting to server, read/write string data
sobj=tcpserver('127.0.0.1',9999);
cobj=tcpclient('127.0.0.1',9999);
sobj.Connected;
cobj.write('Hello Server');
sobj.read()
sobj.write('Hello Client');
cobj.read()
sobj.close();
cobj.close();
ans = Hello Server
ans = Hello Client
Connecting to server, read/write numeric data
sobj=tcpserver('127.0.0.1',9999);
cobj=tcpclient('127.0.0.1',9999);
sobj.Connected;
data=[1,2,3,4];
cobj.write(data,'double');
clientdata=sobj.read(4,'double')
data=99;
sobj.write(data,'int32');
serverdata=cobj.read(1,'int32')
sobj.close();
cobj.close();
clientdata = [Matrix] 1 x 4
1  2  3  4
serverdata = 99