<div class="meta" robots="noindex">

</div>

Class

# Xojo.Net.TCPSocket

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2020r2. Please use `TCPSocket</api/networking/tcpsocket>` as a replacement.

</div>

## Description

This class is used for TCP/IP communication.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                | Type                                                  | Read-Only | Shared |
|-----------------------------------------------------|-------------------------------------------------------|-----------|--------|
| `Address<xojo.net.tcpsocket.address>`               | `Text</api/deprecated/text>`                          |           |        |
| `BytesAvailable<xojo.net.tcpsocket.bytesavailable>` | `UInteger</api/data_types/additional_types/uinteger>` | ✓         |        |
| `IsConnected<xojo.net.tcpsocket.isconnected>`       | `Boolean</api/data_types/boolean>`                    | ✓         |        |
| `Port<xojo.net.tcpsocket.port>`                     | `Int32</api/data_types/additional_types/int32>`       |           |        |
| `SSLSetting<xojo.net.tcpsocket.sslsetting>`         | SSLSettings                                           |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                              | Parameters                                                       | Returns                                     | Shared |
|---------------------------------------------------|------------------------------------------------------------------|---------------------------------------------|--------|
| `AvailableData<xojo.net.tcpsocket.availabledata>` |                                                                  | `MemoryBlock</api/language/memoryblock>`    |        |
| `Connect<xojo.net.tcpsocket.connect>`             |                                                                  |                                             |        |
| `Disconnect<xojo.net.tcpsocket.disconnect>`       |                                                                  |                                             |        |
| `Handle<xojo.net.tcpsocket.handle>`               | type As `Xojo.Net.TCPSocket</api/deprecated/xojo.net.tcpsocket>` | `Ptr</api/data_types/additional_types/ptr>` |        |
| `ReadData<xojo.net.tcpsocket.readdata>`           | length As `Integer</api/data_types/integer>`                     | `MemoryBlock</api/language/memoryblock>`    |        |
| `WriteData<xojo.net.tcpsocket.writedata>`         | data As `MemoryBlock</api/language/memoryblock>`                 |                                             |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                  | Parameters                                                  | Returns |
|-------------------------------------------------------|-------------------------------------------------------------|---------|
| `ConfigureSocket<xojo.net.tcpsocket.configuresocket>` |                                                             |         |
| `Connected<xojo.net.tcpsocket.connected>`             |                                                             |         |
| `DataAvailable<xojo.net.tcpsocket.dataavailable>`     |                                                             |         |
| `Disconnected<xojo.net.tcpsocket.disconnected>`       |                                                             |         |
| `Error<xojo.net.tcpsocket.error>`                     | err As `RuntimeException</api/exceptions/runtimeexception>` |         |

## Enumerations

<div id="xojo.net.tcpsocket.handletypes">

<div class="rst-class">

forsearch

</div>

</div>

Xojo.Net.TCPSocket.HandleTypes

### HandleTypes

Available handle types. (FileDescriptor, CFReadStream, CFWriteStream)

| Enum           | Description |
|----------------|-------------|
| FileDescriptor |             |
| CFReadStream   |             |
| CFWriteStream  |             |

## Property descriptions

<div id="xojo.net.tcpsocket.address">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.Address

**Address** As `Text</api/deprecated/text>`

The TCP/IP address to connect with.

<div id="xojo.net.tcpsocket.bytesavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.BytesAvailable

**BytesAvailable** As `UInteger</api/data_types/additional_types/uinteger>`

The number of bytes of data that are available in the internal receive buffer. You can get the data by calling the ReadData method.

This property is read-only.

<div id="xojo.net.tcpsocket.isconnected">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.IsConnected

**IsConnected** As `Boolean</api/data_types/boolean>`

Indicates whether the socket is currently connected.

This property is read-only.

<div id="xojo.net.tcpsocket.port">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.Port

**Port** As `Int32</api/data_types/additional_types/int32>`

The port to bind on or connect to.

On most operating systems, attempting to bind on a port less than 1024 (without administrator privileges) causes an Error event. You need to set the port property explicitly before any call to Connect as the Port property is changed to reflect the actual port that the OS has bound to.

<div id="xojo.net.tcpsocket.sslsetting">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.SSLSetting

**SSLSetting** As SSLSettings

Specifies the SSL settings for the socket.

## Method descriptions

<div id="xojo.net.tcpsocket.availabledata">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.AvailableData

**AvailableData** As `MemoryBlock</api/language/memoryblock>`

Returns the data available in the receive buffer.

<div id="xojo.net.tcpsocket.connect">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.Connect

**Connect**

Attempts to connect to the specified address and port.

<div id="xojo.net.tcpsocket.disconnect">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.Disconnect

**Disconnect**

Disconnects the socket, resets it, and calls the Disconnected event handler.

<div id="xojo.net.tcpsocket.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.Handle

**Handle**(type As `Xojo.Net.TCPSocket</api/deprecated/xojo.net.tcpsocket>`) As `Ptr</api/data_types/additional_types/ptr>`

Gets the specified OS handle for the socket.

<div id="xojo.net.tcpsocket.readdata">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.ReadData

**ReadData**(length As `Integer</api/data_types/integer>`) As `MemoryBlock</api/language/memoryblock>`

Reads length bytes from the socket.

This reads the bytes that are in the buffer. Not all data that was sent will necessarily appear in the buffer right away.

``` xojo
' Read all data that is available in the buffer
Var data As MemoryBlock
data = myTCPSocket.ReadData(myTCPSocket.BytesAvailable)
```

<div id="xojo.net.tcpsocket.writedata">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.WriteData

**WriteData**(data As `MemoryBlock</api/language/memoryblock>`)

Writes data to the socket.

## Event descriptions

<div id="xojo.net.tcpsocket.configuresocket">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.ConfigureSocket

**ConfigureSocket**

Called when the socket needs to be configured.

<div id="xojo.net.tcpsocket.connected">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.Connected

**Connected**

Called when the socket connects to another socket or server.

<div id="xojo.net.tcpsocket.dataavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.DataAvailable

**DataAvailable**

Called when additional data has come into the internal receive buffer.

It is your responsibility to read the data from the buffer using the ReadData method.

<div class="warning">

<div class="title">

Warning

</div>

This event is reentrant which means you should **not** process the data you have received in this event. Instead, copy it into a property and then use a `Timer</api/language/timer>` to process the data. Specifically, use `Timer<timer.calllater>` method.

</div>

<div id="xojo.net.tcpsocket.disconnected">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.Disconnected

**Disconnected**

Called when the socket disconnects after previously being connected.

<div id="xojo.net.tcpsocket.error">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Net.TCPSocket.Error

**Error**(err As `RuntimeException</api/exceptions/runtimeexception>`)

Called when an error occurs, with err containing the exception causing the error.

## Notes

You can add a "Generic Object" control your view and change its Super to "<span class="title-ref">Xojo.Net.TCPSocket</span>" to create a subclass directly on the view, giving you access to the events. You can also create your own subclass or use AddHandler to access the events.

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; Xojo.Net.SSLSettings class
