Class

Xojo.Net.TCPSocket


Warning

This item was deprecated in version 2020r2. Please use TCPSocket as a replacement.

Description

This class is used for TCP/IP communication.

Properties

Name

Type

Read-Only

Shared

Address

Text

BytesAvailable

UInteger

IsConnected

Boolean

Port

Int32

SSLSetting

SSLSettings

Methods

Name

Parameters

Returns

Shared

AvailableData

MemoryBlock

Connect

Disconnect

Handle

type As Xojo.Net.TCPSocket

Ptr

ReadData

length As Integer

MemoryBlock

WriteData

data As MemoryBlock

Enumerations

Xojo.Net.TCPSocket.HandleTypes

HandleTypes

Available handle types. (FileDescriptor, CFReadStream, CFWriteStream)

Enum

Description

FileDescriptor

CFReadStream

CFWriteStream

Property descriptions


Xojo.Net.TCPSocket.Address

Address As Text

The TCP/IP address to connect with.


Xojo.Net.TCPSocket.BytesAvailable

BytesAvailable As 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.


Xojo.Net.TCPSocket.IsConnected

IsConnected As Boolean

Indicates whether the socket is currently connected.

This property is read-only.


Xojo.Net.TCPSocket.Port

Port As 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.


Xojo.Net.TCPSocket.SSLSetting

SSLSetting As SSLSettings

Specifies the SSL settings for the socket.

Method descriptions


Xojo.Net.TCPSocket.AvailableData

AvailableData As MemoryBlock

Returns the data available in the receive buffer.


Xojo.Net.TCPSocket.Connect

Connect

Attempts to connect to the specified address and port.


Xojo.Net.TCPSocket.Disconnect

Disconnect

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


Xojo.Net.TCPSocket.Handle

Handle(type As Xojo.Net.TCPSocket) As Ptr

Gets the specified OS handle for the socket.


Xojo.Net.TCPSocket.ReadData

ReadData(length As Integer) As 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.

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

Xojo.Net.TCPSocket.WriteData

WriteData(data As MemoryBlock)

Writes data to the socket.

Event descriptions


Xojo.Net.TCPSocket.ConfigureSocket

ConfigureSocket

Called when the socket needs to be configured.


Xojo.Net.TCPSocket.Connected

Connected

Called when the socket connects to another socket or server.


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.

Warning

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 to process the data. Specifically, use Timer method.


Xojo.Net.TCPSocket.Disconnected

Disconnected

Called when the socket disconnects after previously being connected.


Xojo.Net.TCPSocket.Error

Error(err As 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 "Xojo.Net.TCPSocket" 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 parent class; Xojo.Net.SSLSettings class