Provides base functionality common to all sockets, including TCP sockets and UDP sockets. More...
Properties
- error : SocketError
- errorString : string
- localAddress : NetworkAddress
- localPort : ushort
- remoteAddress : NetworkAddress
- remoteName : string
- remotePort : ushort
- state : SocketState
- textEncoding : TextEncoding
- textMode : bool
- valid : bool
Signals
- dataReceived(object data)
- remoteChanged()
Methods
- abort()
- bool bind()
- bool bind(var address)
- bool bind(var address, ushort port)
- bool bind(var address, ushort port, bindmode mode)
- close()
- connectToHost(string hostName, ushort port)
- connectToHost(string hostName, ushort port, openmode mode)
- connectToHost(string hostName, ushort port, openmode mode, protocol protocol)
- disconnectFromHost()
- sendData(var data)
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.
Name | Value |
---|---|
AbstractSocket.StateUnconnected | 0 |
AbstractSocket.StateHostLookup | 1 |
AbstractSocket.StateConnecting | 2 |
AbstractSocket.StateConnected | 3 |
AbstractSocket.StateBound | 4 |
AbstractSocket.StateListening | 5 |
AbstractSocket.StateClosing | 6 |
OpenMode enumeration
This enum describes the different flags you can pass to modify the behavior of the method connectToHost.
Name | Value |
---|---|
AbstractSocket.OpenModeReadOnly | 1 |
AbstractSocket.OpenModeWriteOnly | 2 |
AbstractSocket.OpenModeReadWrite | 3 |
AbstractSocket.OpenModeText | 16 |
BindMode enumeration
This enum describes the different flags you can pass to modify the behavior of the method bind.
Name | Value |
---|---|
AbstractSocket.BindModeDefaultForPlatform | 0 |
AbstractSocket.BindModeShareAddress | 1 |
AbstractSocket.BindModeDontShareAddress | 2 |
AbstractSocket.BindModeReuseAddressHint | 4 |
Protocol enumeration
This enum determines the protocol used when connecting to another device.
Name | Value |
---|---|
AbstractSocket.ProtocolUnknown | -1 |
AbstractSocket.ProtocolIPv4 | 0 |
AbstractSocket.ProtocolIPv6 | 1 |
AbstractSocket.ProtocolAny | 2 |
SocketError enumeration
This enum describes socket errors that can occur.
Name | Value |
---|---|
AbstractSocket.ErrorUnknown | -1 |
AbstractSocket.ErrorConnectionRefused | 0 |
AbstractSocket.ErrorRemoteHostClosed | 1 |
AbstractSocket.ErrorHostNotFound | 2 |
AbstractSocket.ErrorSocketAccess | 3 |
AbstractSocket.ErrorSocketResource | 4 |
AbstractSocket.ErrorSocketTimeout | 5 |
AbstractSocket.ErrorDatagramTooLarge | 6 |
AbstractSocket.ErrorNetwork | 7 |
AbstractSocket.ErrorAddressInUse | 8 |
AbstractSocket.ErrorSocketAddressNotAvailable | 9 |
AbstractSocket.ErrorUnsupportedSocketOperation | 10 |
AbstractSocket.ErrorUnfinishedSocketOperation | 11 |
AbstractSocket.ErrorProxyAuthenticationRequired | 12 |
AbstractSocket.ErrorSslHandshakeFailed | 13 |
AbstractSocket.ErrorProxyConnectionRefused | 14 |
AbstractSocket.ErrorProxyConnectionClosed | 15 |
AbstractSocket.ErrorProxyConnectionTimeout | 16 |
AbstractSocket.ErrorProxyNotFound | 17 |
AbstractSocket.ErrorProxyProtocol | 18 |
AbstractSocket.ErrorOperation | 19 |
AbstractSocket.ErrorSslInternal | 20 |
AbstractSocket.ErrorSslInvalidUserData | 21 |
AbstractSocket.ErrorTemporary | 22 |
TextEncoding enumeration
This enum describes the form of text encoding being accepted by the port.
Name | Value |
---|---|
AbstractSocket.TextEncodingUnknown | -1 |
AbstractSocket.TextEncodingUtf8 | 0 |
AbstractSocket.TextEncodingLatin1 | 1 |
AbstractSocket.TextEncodingLocal8Bit | 2 |
Property Documentation
[read-only] localAddress : NetworkAddress |
Returns the host address of the local socket if available.
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.
Returns the peer name associated with the port by the connectToHost method. If one has not been declared, returns an empty string.
Returns the number of the remote port if the socket is connected. Otherwise, returns 0.
Returns the form of text encoding, described in the corresponding enum, that the port is currently using.
Returns true if the given file is declared to be a text file. Otherwise, returns false.
Returns true if socket is valid and ready for use. Otherwise, returns false.
Signal Documentation
Signal emitted when data has been received through this socket.
Note: The corresponding handler is onDataReceived
.
Signal emitted when a remote port is found, connected, or disconnected.
Note: The corresponding handler is onRemoteChanged
.
Method Documentation
Binds socket to the defined address.
The address parameter
Address to bind the socket to.
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.
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.
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.
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.
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.
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.