AbstractSocket QML Type

Provides base functionality common to all sockets, including TCP sockets and UDP sockets. More...

Import Statement: import ArcGIS.AppFramework.Networking 1.0
Inherited By:

TcpSocket and UdpSocket

Properties

Signals

Methods

Detailed Description

The AbstractSocket component contains all common functionality for socket types. The component can be used to define details such as port and address, connect or disconnect from a host, or manage the data sent through it.

AbstractSocket is an abstract component, and as such can't be called by itself, it must be called through the UdpSocket component. This code sample from AppStudio Player demonstrates using UdpSocket in this way, returning information from the SSDP listener when a datagram has been received.

UdpSocket {
    id: socket

    onDatagramReceived: {
        console.log("datagram: ", datagram);
        console.log("address: ", address);
        console.log("port: ", port);
    }

    onStateChanged: {
        console.log("SSDPListener status:", state);
    }

    onErrorChanged: {
        console.log("SSDPListener error:", error, errorString);
    }
}

Enumerations

SocketState enumeration

This enum describes different states a socket can be in.

NameValue
AbstractSocket.StateUnconnected0
AbstractSocket.StateHostLookup1
AbstractSocket.StateConnecting2
AbstractSocket.StateConnected3
AbstractSocket.StateBound4
AbstractSocket.StateListening5
AbstractSocket.StateClosing6

OpenMode enumeration

This enum describes the different flags you can pass to modify the behavior of the method connectToHost.

NameValue
AbstractSocket.OpenModeReadOnly1
AbstractSocket.OpenModeWriteOnly2
AbstractSocket.OpenModeReadWrite3
AbstractSocket.OpenModeText16

BindMode enumeration

This enum describes the different flags you can pass to modify the behavior of the method bind.

NameValue
AbstractSocket.BindModeDefaultForPlatform0
AbstractSocket.BindModeShareAddress1
AbstractSocket.BindModeDontShareAddress2
AbstractSocket.BindModeReuseAddressHint4

Protocol enumeration

This enum determines the protocol used when connecting to another device.

NameValue
AbstractSocket.ProtocolUnknown-1
AbstractSocket.ProtocolIPv40
AbstractSocket.ProtocolIPv61
AbstractSocket.ProtocolAny2

SocketError enumeration

This enum describes socket errors that can occur.

NameValue
AbstractSocket.ErrorUnknown-1
AbstractSocket.ErrorConnectionRefused0
AbstractSocket.ErrorRemoteHostClosed1
AbstractSocket.ErrorHostNotFound2
AbstractSocket.ErrorSocketAccess3
AbstractSocket.ErrorSocketResource4
AbstractSocket.ErrorSocketTimeout5
AbstractSocket.ErrorDatagramTooLarge6
AbstractSocket.ErrorNetwork7
AbstractSocket.ErrorAddressInUse8
AbstractSocket.ErrorSocketAddressNotAvailable9
AbstractSocket.ErrorUnsupportedSocketOperation10
AbstractSocket.ErrorUnfinishedSocketOperation11
AbstractSocket.ErrorProxyAuthenticationRequired12
AbstractSocket.ErrorSslHandshakeFailed13
AbstractSocket.ErrorProxyConnectionRefused14
AbstractSocket.ErrorProxyConnectionClosed15
AbstractSocket.ErrorProxyConnectionTimeout16
AbstractSocket.ErrorProxyNotFound17
AbstractSocket.ErrorProxyProtocol18
AbstractSocket.ErrorOperation19
AbstractSocket.ErrorSslInternal20
AbstractSocket.ErrorSslInvalidUserData21
AbstractSocket.ErrorTemporary22

TextEncoding enumeration

This enum describes the form of text encoding being accepted by the port.

NameValue
AbstractSocket.TextEncodingUnknown-1
AbstractSocket.TextEncodingUtf80
AbstractSocket.TextEncodingLatin11
AbstractSocket.TextEncodingLocal8Bit2

Property Documentation

[read-only] error : SocketError

Returns the type of error that last occurred.


[read-only] errorString : string

Returns a human-readable string describing the error state.


[read-only] localAddress : NetworkAddress

Returns the host address of the local socket if available.


[read-only] localPort : ushort

Returns the host port number of the local socket if available. Otherwise, returns 0.


[read-only] remoteAddress : NetworkAddress

Returns the remote host address of the port.


[read-only] remoteName : string

Returns the peer name associated with the port by the connectToHost method. If one has not been declared, returns an empty string.


[read-only] remotePort : ushort

Returns the number of the remote port if the socket is connected. Otherwise, returns 0.


[read-only] state : SocketState

Returns the state of the socket.


textEncoding : TextEncoding

Returns the form of text encoding, described in the corresponding enum, that the port is currently using.


textMode : bool

Returns true if the given file is declared to be a text file. Otherwise, returns false.


[read-only] valid : bool

Returns true if socket is valid and ready for use. Otherwise, returns false.


Signal Documentation

dataReceived(object data)

Signal emitted when data has been received through this socket.

Note: The corresponding handler is onDataReceived.


remoteChanged()

Signal emitted when a remote port is found, connected, or disconnected.

Note: The corresponding handler is onRemoteChanged.


Method Documentation

abort()


bool bind()

Binds socket to a random available port.


bool bind(var address)

Binds socket to the defined address.

The address parameter

Address to bind the socket to.


bool bind(var address, ushort port)

Binds socket to the defined address and port.

The address parameter

Address to bind the socket to.

The port parameter

Port to bind the socket to.


bool bind(var address, ushort port, bindmode mode)

Binds socket to the defined address and port, with respect to the stated bind mode.

The address parameter

Address to bind the socket to.

The port parameter

Port to bind the socket to.

The mode parameter

The flag used to define behavior of the bind.


close()

Closes and disconnects the defined device and socket.


connectToHost(string hostName, ushort port)

Attempts to connect to host of the defined name, on the given port.

The hostName parameter

Name of the host; either an IP address or web address.

The port parameter

Port to connect to the host through.


connectToHost(string hostName, ushort port, openmode mode)

Attempts to connect to host of the defined name, on the given port and with the stated open mode.

The hostName parameter

Name of the host; either an IP address or web address.

The port parameter

Port to connect to host through.

The mode parameter

Flag used to define behavior of open port.


connectToHost(string hostName, ushort port, openmode mode, protocol protocol)

Network protocol to use in connecting; IPv4 or IPv6.

The hostName parameter

Name of the host; either an IP address or web address.

The port parameter

Port to connect to the host through.

The mode parameter

Flag used to define behavior of open port.

The protocol parameter

Network protocol to use in connecting; IPv4 or IPv6.


disconnectFromHost()

Attempts to close the socket.


sendData(var data)

Sends the declared data through the open port, checking to ensure it matches the declared form of text encoding. If the encoding does not match, it will return an error.

The data parameter

The data you want to send. It needs to match the form of encoding declared for the port.


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.