---
title: "TcpClient (_TcpClient class)"
canonical: "https://docs.cuesystem.com/space/CVCHELP/522289167/TcpClient%20(_TcpClient%20class)"
format: markdown
---
> Macro (toc)

---

# ClearReceiveBuffer

The command removes received data from a receive buffer. 

#### Syntax 

```visualbasic
Function ClearReceiveBuffer()
```

#### Example 

```visualbasic
TcpClient1.ClearReceiveBuffer()
```

# Connect

The command opens a connection to the server. It returns **True** on success or **False** if an error occurs. 

#### Syntax 

```visualbasic
Function Connect( 
  serveraddress As Text, 
  serverport As Long, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

serveraddress 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the IP address of a server. It is specified by numbers (e.g. "192.168.30.5") or a domain name (e.g. "mycompany.com"). 

serverport 

<u>[Long](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is the port of a server. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the connection timeout. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

**True** on success 

**False** if an error occurs. A function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The following errors may occur: <u>[87](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#87)</u>, <u>[88](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#88)</u>, <u>[89](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#89)</u>, <u>[90](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#90)</u>, <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[93](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#93)</u>, <u>[94](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#94)</u>. 

#### Example 

```visualbasic
Var RecvData As ByteString[100] 

// connect to address "192.168.100.100", TCP HTTP port 
If TcpClient1.Connect("192.168.100.100", 80) = True Then 
  TcpClient1.Send(&S"SomeRequest") 
  // wait for an answer 
  If TcpClient1.Receive(RecvData) = True Then 
  // process answer 
  End If 
  TcpClient1.Disconnect() 
End If
```

# ConnectSSL

The command opens a connection to the server and uses the Secure Socket  Layer or Transport Layer Security protocol. ConnectSSL supports SSL 3.0, TLS 1.0, TLS 1.1, TLS 1.2 and TLS 1.3 protocols. It returns **True** on success or **False** if an error occurs. 

#### Syntax 

```visualbasic
Function ConnectSSL( 
  serveraddress As Text, 
  serverport As Long, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

serveraddress 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the IP address of a server. It is specified by numbers (e.g. "192.168.30.5") or a domain name (e.g. "mycompany.com"). 

serverport 

<u>[Long](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is the port of a server. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the connection timeout. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

**True** on success 

**False** if an error occurs. A function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The following errors may occur: <u>[87](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#87)</u>, <u>[88](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#88)</u>, <u>[89](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#89)</u>, <u>[90](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#90)</u>, <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[93](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#93)</u>, <u>[94](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#94)</u>. 

#### Example 

```visualbasic
Var RecvData As ByteString[100] 

// connect to address "192.168.100.100", TCP HTTPS port 
If TcpClient1.ConnectSSL("192.168.100.100", 443) = True Then 
  TcpClient1.Send(&S"SomeRequest") 
  // wait for an answer 
  If TcpClient1.Receive(RecvData) = True Then 
    // process answer 
  End If 
  TcpClient1.Disconnect() 
End If
```

# ConnectSSH

The command opens a connection to the SSH server. It returns **True** on success or **False** if an error occurs.  Command supports SSH2 protocol and authentication method **password**. 


> ℹ️ This command is not supported in simulation mode in the CVC and always returns False.

> ℹ️ Authentication methods **publickey** and **password+publickey** are not supported.



#### Syntax 

```visualbasic
Function ConnectSSH( 
  serveraddress As Text, 
  username As Text, 
  password As Text, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

serveraddress 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the IP address of a server. It is specified by numbers (e.g. "192.168.30.5") or a domain name (e.g. "mycompany.com"). It is possible to specify a port in this parameter (e.g. "192.168.30.5**:200**", "mycompany.com**:4359**"). If the port is not specified, default SSH port 22 is used. 

username 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the user name. 

username 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is a password. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the connection timeout. 

#### Return value* *

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

**True** on success 

**False** if an error occurs. A function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The following errors may occur: <u>[87](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#87)</u>, <u>[88](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#88)</u>, <u>[89](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#89)</u>, <u>[90](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#90)</u>, <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[93](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#93)</u>, <u>[94](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#94)</u>, <u>[226](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#226)</u>, <u>[228](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#228)</u>, <u>[229](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#229)</u> . 

#### Example 

```visualbasic
Var RecvData As ByteString[100] 

// connect to SSH server on IP address "192.168.100.100" 
If TcpClient1.ConnectSSH("192.168.100.100","admin", "admin") = True Then 
  TcpClient1.Send(&S"SomeRequest") 
  // wait for an answer 
  If TcpClient1.Receive(RecvData) = True Then 
    // process answer 
  End If 
  TcpClient1.Disconnect() 
End If
```

# Disconnect

The command disconnects a client from the server. 

#### Syntax* *

```visualbasic
Function Disconnect()
```

#### Example 

```visualbasic
Var RecvData As ByteString[100] 

// connect to address "192.168.100.100", TCP HTTP port 
If TcpClient1.Connect("192.168.100.100", 80) = True Then 
  TcpClient1.Send(&S"SomeRequest") 
  // wait for an answer 
  If TcpClient1.Receive(RecvData) = True Then 
    // process answer 
  End If 
  TcpClient1.Disconnect() 
End If
```

# EnableKeepAlivePackets

The command enables TCP to keep the alive mechanism on the connected TCP channel. See [https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) , [https://en.wikipedia.org/wiki/Keepalive](https://en.wikipedia.org/wiki/Keepalive) .

#### Syntax 

```visualbasic
Function EnableKeepAlivePackets(
  keepalive_time As Time, 
  Optional interval As Time := :2, 
  Optional probes As Long := 5) 
As Boolean
```

#### Parameters 

keepalive_time 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> is the duration between two keepalive transmissions in idle condition. Time must be between 1 second and 2 hours. 

interval 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 2 seconds. It is the duration between two successive keepalive retransmissions if acknowledgment of the previous keepalive transmission is not received. Time must be between 1 second and 60 seconds. 

probes 

<u>[Long](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> Optional, defaults to 5. It is the number of retransmissions to be carried out before declaring that the remote end is not available. The value must be between 3 and 100. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

**True** on success 

**False** if an error occurs. A function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>345</u>. 

#### Example 

```visualbasic
Var data As ByteString[1000] 
Var anythingreceived As Boolean 
Var lasterror As Long 

If TcpClient1.Connect("192.168.30.171",3000) Then 
  DebugPrint("CONNECT OK") 
  TcpClient1.EnableKeepAlivePackets(:2,:1,3) 
  Do While True 
    anythingreceived := TcpClient1.ReceiveAnything(data,:5) 
    lasterror := GetLastError() 
    If anythingreceived = False Then 
      If lasterror = 92 Then // receive timeout 
        DebugPrintFormat("ReceiveAnything timeout")   
      Else  
        DebugPrint("TCP connection with the device has been lost") 
        Exit Do 
      End If  
    End If 
  End Do 
Else 
  DebugPrint("Cannot connect to device") 
End If
```

# GetMyIpAddress

The command retrieves the controller’s IP address and port of the connection. It returns **True** on success or **False** if an error occurs. 

#### Syntax 

```visualbasic
Function GetMyIpAddress( 
  ByRef ipaddress As Text, 
  ByRef port As Long) 
As Boolean
```

#### Parameters 

ipaddress  

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the IP address of the controller. 

port  

<u>[Long](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is the port of the connection on the controller. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

**True** on success 

**False** if an error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur:  <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[139](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#139)</u>. 

# Receive

This function receives data from the channel’s receive buffer. At first *receiveddata* variable is cleared. The function terminates if the timeout expired or *maxbytestoreceive* bytes were received or the server closes the connection. It returns **True** if any data is received. It returns **False** if no data is received within the timeout limit or some error occurs. If some data is received, data is moved from the channel’s receive buffer to *receiveddata*. If no data is received, the *receiveddata* remains empty. 

#### Syntax 

```visualbasic
Function Receive( 
  ByRef receiveddata As ByteString, 
  Optional timeout As Time := :10.0, 
  Optional maxbytestoreceive As Long := 0) 
As Boolean
```

#### Parameters 

receiveddata 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a variable where received data is placed to. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the receive timeout. 

maxbytestoreceive 

<u>[Long](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> Optional, defaults to 0. It is the maximum number of received bytes stored in the parameter data. If maxsize is equal to 0 or greater than a declared length of the data string, the maxbytestoreceive is set to the declared length. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

**True** if any data is received.  

**False** if no data is received within the timeout limit or some error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[92](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#92)</u>. 

#### Example 

```visualbasic
Var RecvData As ByteString[100] 

// connect to address "192.168.100.100", TCP HTTP port 
If TcpClient1.Connect("192.168.100.100", 80) = True Then 
  TcpClient1.Send(&S"SomeRequest") 
  // wait for an answer 
  If TcpClient1.Receive(RecvData) = True Then 
    // process answer 
  End If 
  TcpClient1.Disconnect() 
End If
```

# ReceiveAnything

This function receives data from the channel’s receive buffer. At first *receiveddata* variable is cleared. The function terminates if the timeout expired or any number of bytes was received or the server closes the connection. The maximum amount of the data read is given by the declared length of the *receiveddata*. It returns **True** if any data is received. It returns **False** if no data is received within the timeout limit or some error occurs. If some data is received, data is moved from the channel’s receive buffer to *receiveddata*. If no data is received, the *receiveddata* remains empty.  

#### Syntax 

```visualbasic
Function ReceiveAnything( 
  ByRef receiveddata As ByteString, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

receiveddata 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a variable where received data is placed to. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the receive timeout. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> 

**True** if any data is received.  

**False** if no data is received within the timeout limit or some error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[92](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#92)</u>. 

# ReceiveAppend

This function receives any data from the channel’s receive buffer. Compared to the function Receive the received data is appended to the end of the current *receivebuffer *content. It means the *receivebuffer *is not cleared. Appended data is removed from the channel’s receive buffer. The maximum length of the data read is limited by several empty bytes in *receivebuffer* (declared length minus actual length at the moment function starts). The function terminates if the timeout expired or any number of bytes was received or the server closes the connection. It returns **True** if any data is received. It returns **False** if no data is received within the timeout limit or some error occurs. If no data is received, the *receivebuffer *is not modified. 

This function is helpful if you need to append any data from the channel, parse it in the same buffer and continue receiving. The command can save one buffer variable. 

#### Syntax 

```visualbasic
Function ReceiveAppend( 
  ByRef receivebuffer As ByteString, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

receivebuffer 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a variable where received data is appended to. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, receive timeout. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

***True*** if any data is received.  

***False*** if no data is received within the timeout limit or some error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[92](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#92)</u>, <u>[145.](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#145)</u> 

# ReceiveFPacket

This function receives the body of a data packet containing the body and footer. Footer is a constant data pattern that terminates the data packet. The body contains a payload of a data packet with variable length. 

Data packet FPacket = Body + Footer. 

The function clears the parameter *receivedbody* at first and then it stores received data to it. Then it moves data from the channel’s receive buffer to *receivedbody* and simultaneously checks data for the footer. If the footer is found it is removed from the *receivedbody*, the function returns **True** and the *receivedbody* contains just the body (payload). If the *receivedbody* is completely filled and the footer is not found or the footer did not follow, then the function returns **False** and all received data remains in *receivedbody*. If the whole data packet is not received within the timeout, then the function returns **False** and all received data remains in *receivedbody*. 

#### Syntax 

```visualbasic
Function ReceiveFPacket( 
  ByRef receivedbody As ByteString, 
  footer As ByteString, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

receivedbody 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a variable where received data is placed to. 

footer 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a non-empty data pattern that terminates a data packet. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the receive timeout. 

#### Return value* *

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

***True*** if the complete footer is received before timeout. 

***False*** if the footer is not received within the timeout limit or some error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[92](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#92)</u>, <u>[153](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#153)</u>, <u>[154.](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#154)</u> 

#### Example 

This example describes how to receive a line of bytes terminated by CR LF (&S"\0D\0A"). 

```visualbasic
Private Var OneLine As ByteString[1024] 

If TcpClient1.ReceiveFPacket(OneLine,&S"\0D\0A") Then   
  // line received, parse variable OneLine 
Else  
  Select GetLastError()  
    Case 91    // error handling 
    Case 92    // error handling 
    Case 154   // error handling 
  End Select  
End If
```

# ReceiveHFPacket

This function receives the body of a data packet containing a header, body, and footer. The header and Footer are constant data patterns that start and terminate data packet. The body contains a payload of a data packet with variable length. 

Data packet HFPacket = Header + Body + Footer. 

The function clears the parameter *receivedbody* at first and waits for the header. All data preceding the header including the header itself are removed from the channel’s receive buffer. If the header is found then all data following the header is moved from the channel’s receive buffer to *receivedbody* and simultaneously checks data for the footer. If the footer is found it is removed from the *receivedbody*, the function returns **True** and the *receivedbody* contains just the body (payload). If the *receivedbody* is completely filled and the footer is not found or the footer did not follow, then the function returns **False** and all received data remains in *receivedbody*. If the whole data packet is not received within the timeout, then the function returns **False** and all received data remains in *receivedbody*. 

#### Syntax 

```visualbasic
Function ReceiveHFPacket( 
  ByRef receivedbody As ByteString, 
  header As ByteString, 
  footer As ByteString, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

receivedbody 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a variable where received data is placed to. 

header 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a non-empty data pattern that starts a data packet. 

footer 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a non-empty data pattern that terminates a data packet. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the receive timeout. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

***True*** if header and footer were received before timeout. 

***False*** if header and footer are not received within the timeout limit or some error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[92](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#92)</u>, <u>[153](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#153)</u>, <u>[154.](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#154)</u> 

#### Example 

This example describes how to receive a packet started by STX (&S"\02") and terminated by ETX (&S"\03"). 

```visualbasic
Private Var Data As ByteString[1024] 

If TcpClient1.ReceiveHFPacket(Data,&S"\02",&S"\03") Then   
  // data received, parse Data 
Else  
  Select GetLastError()  
    Case 91    // error handling 
    Case 92    // error handling 
    Case 154   // error handling    
  End Select  
End If
```

# ReceiveHLPacket

This function receives the body of a data packet containing a header and body with a known length. The header is a constant data pattern that starts the data packet. The body contains a payload of a data packet with a known length. 

Data packet HLPacket = Header + Body with known length. 

The function clears the parameter *receivedbody* at first and waits for the header. All data preceding the header including the header itself are removed from the channel’s receive buffer. If the header is found then the *bodylength* of bytes following the header is moved from the channel’s receive buffer to *receivedbody*. If the *bodylength* number of bytes was received, the function returns **True** and *receivedbody* contains just the body (payload). If the whole data packet is not received within the timeout, then the function returns **False** and all received data remains in *receivedbody*. If the *receivedbody* is full and *bodylength* is not reached, then the function returns **False** and all received data remains in *receivedbody*. 

#### Syntax 

```visualbasic
Function ReceiveHLPacket( 
  ByRef receivedbody As ByteString, 
  header As ByteString, 
  bodylength As Long, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

receivedbody 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a variable where received data is placed to. 

header 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a non-empty data pattern that starts a data packet. 

bodylength 

<u>[Long](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is the length of the body. It must be greater than 0. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the receive timeout. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

***True*** if header and data with *bodylength* were received before timeout.  

***False*** if header or data with *bodylength* are not received within the timeout limit or some error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[92](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#92)</u>, <u>[153](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#153)</u>, <u>[154.](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#154)</u> 

#### Example 

This example describes how to receive a packet started by &S"*" with a body length of 5 bytes. 

```visualbasic
Private Var Data As ByteString[5] 
Private Var BodyLength As Long := 5 

If TcpClient1.ReceiveHLPacket(Data,&S"*", BodyLength) Then   
  // data received, parse Data 
Else  
  Select GetLastError()  
    Case 91    // error handling 
    Case 92 // error handling 
    Case 154 // error handling 
  End Select  
End If
```

# ReceiveSyncFrame

This function waits for data pattern defined by parameter *syncframe*.  The function returns **True** if the *syncframe* is received before timeout. If *timeout* exceeds without receiving *syncframe*, the function returns **False**. 

#### Syntax 

```visualbasic
Function ReceiveSyncFrame( 
  syncframe As ByteString, 
  Optional timeout As Time := :10.0) 
As Boolean
```

#### Parameters 

syncframe 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a non-empty data pattern. 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the receive timeout. 

#### Return value* *

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

***True*** if *syncframe* was received before timeout.  

***False*** if timeout exceeds without receiving *syncframe* or some error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[92](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#92)</u>, <u>[153.](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#153)</u> 

#### Example 

This example describes how to receive data from &S"@POWERON" and &S"@POWEROFF". 

```visualbasic
Private Var Data As ByteString[8] 

If TcpClient1.ReceiveSyncFrame(&S"@",:2.0) Then  
  // sync frame @ is received 
  If TcpClient1.Receive(Data,8,:0.05) Then 
    Select Data 
      Case &S"POWERON" // power is on 
      Case &S"POWEROFF" // power is off 
    End Select 
  End If 
Else  
  // error handling 
End If
```

# Send

The function sends data to the channel. It returns **True** on success or **False** if a *datatosend* is not accessible. 

#### Syntax 

```visualbasic
Function Send(datatosend As ByteString) As Boolean
```

#### Parameters 

datatosend 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is the data to be sent. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> 

***True*** on success 

***False*** if the *datatosend* is not accessible or some error occurs. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>. 

#### Example 

```visualbasic
Var RecvData As ByteString[100] 

// connect to address "192.168.100.100", TCP HTTP port 
If TcpClient1.Connect("192.168.100.100", 80) = True Then 
  TcpClient1.Send(&S"SomeRequest") 
    // wait for an answer 
  If TcpClient1.Receive(RecvData) = True Then 
    // process answer 
  End If 
  TcpClient1.Disconnect() 
End If
```

# VerifyCertificate

The command checks an SSL certificate from a server. 

#### Syntax 

```visualbasic
Function VerifyCertificate() As Boolean
```

#### Example 

```visualbasic
If TcpClient1.ConnectSSL("www.google.com", 443) = True Then 
  If TcpClient1.VerifyCertificate() Then 
    // certificate is valid
  End If  
  TcpClient1.Disconnect() 
End If
```

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

***True*** if an SSL certificate is valid.  

***False*** if an SSL certificate is not valid. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[218](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#218)</u>, <u>[219](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#219)</u>, <u>[220](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#220)</u>, <u>[221](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#221)</u>, <u>[222](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#222)</u>, <u>[223](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#223)</u>.  

# WaitForData

This function waits for any data on the channel. The function doesn’t receive any data, which means the content of the channel’s receive buffer is not changed. If the channel’s receive buffer is not empty the function returns **True** immediately. If the channel’s receive buffer is empty and some data are received before *timeout*, the function returns **True**. The function returns **False** if no data is received before *timeout*. 

This function is necessary if you need to receive and process any asynchronous data. 

#### Syntax 

```visualbasic
Function WaitForData(Optional timeout As Time := :10.0) As Boolean
```

#### Parameters 

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to 10 seconds. It is the receive timeout. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u>  

***True*** if the channel is not empty or if some data are received before timeout. 

***False*** if timeout exceeds without any incoming data. A function GetLastError returns the error number that occurred while executing the command. The following errors may occur: <u>[91](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#91)</u>, <u>[92](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#92)</u>.