---
title: "TcpServer (_TcpServer class)"
canonical: "https://docs.cuesystem.com/space/CVCHELP/522223630/TcpServer%20(_TcpServer%20class)"
format: markdown
---
> Macro (toc)

---

# Close

The command closes the communication. 

#### Syntax* *

```visualbasic
Function Close()
```

#### Example 

```visualbasic
TcpServer1.Close()
```

# GetClient

The command returns information about a remote client. The client is specified by its client number. 

A function [<u>GetLastError</u>](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError) returns the error number that occurred while executing the command. The errors that can happen: [<u>98</u>](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#98). 

#### Syntax 

```visualbasic
Function GetClient(clientnumber As Long) As AddressOf _TcpRemoteClient
```

#### Parameters 

clientnumber 

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

#### Return value 

[<u>AddressOf</u>](/wiki/spaces/CVCHELP/pages/522682857/Other+operators#AddressOf) <u>[_TcpRemoteClient class](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/522289192)</u>. It is information about a Tcp remote client. It is Nothing if an error occurs. A function GetLastError returns the error number. 

#### Example 

```visualbasic
Function TCPServerStart() 
  If TcpServer1.Open(23) = True Then 
    StartProcess TcpClientWorker(TcpServer1.GetClient(1)) 
  End If 
End Function 

Process TcpClientWorker(Client As AddressOf _TcpRemoteClient) 
  Var ClienIpAdd As Text[20] 
  Var ClientPort As Long  
  Var RecvData As ByteString[100] 

  Do While True 
    If Client.WaitForConnect() = True Then 
      Client.Send(&S"I am connected.") 
      Client.GetIpAddress(ClienIpAdd, ClientPort) 
      If Client.Receive(RecvData) = True Then 
        // process answer 
        Client.Send(&S"Reply") 
      End If 
      Client.Disconnect() 
    End If 
  End Do 
End Process
```

# Open

The command opens a connection on a specified TCP port. It returns True on success or False if an error occurs. 

A function [<u>GetLastError</u>](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError) returns the error number that occurred while executing the command. The errors that can happen: [<u>90</u>](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#90), [<u>95</u>](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#95), [<u>96</u>](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#96), [<u>97</u>](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#97). 

#### Syntax 

```visualbasic
Function Open( 
  tcpport As Long, 
  Optional maxnumberofclients As Long := 1) 
As Boolean
```

#### Parameters 

tcpport 

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

maxnumberofclients 

[<u>Long</u>](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long) Optional, defaults to 1. It is the maximum number of clients. The maximum possible number of clients is 4.  

#### Return value 

[<u>Boolean</u>](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean) It is True on success or False if an error occurs. A function GetLastError returns the error number. 

#### Example 

```visualbasic
If TcpServer1.Open(23) = True Then 
  //... 
End If
```