Enumerationmigueldeicaza.swiftgodot 0.46.0SwiftGodot
WriteMode
WebSocketPeer.swift:26enum WriteMode
Cases
case text
Specifies that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed).
case binary
Specifies that WebSockets messages should be transferred as binary payload (any byte combination is allowed).
Other members in extension
View members
Hide members
This section is hidden by default because it contains too many (23) members.
Types
Type members
Instance members
var handshakeHeaders: PackedStringArray
The extra HTTP headers to be sent during the WebSocket handshake.
var inboundBufferSize: Int32
The size of the input buffer in bytes (roughly the maximum amount of memory that will be allocated for the inbound packets).
var maxQueuedPackets: Int32
The maximum amount of packets that will be allowed in the queues (both inbound and outbound).
var outboundBufferSize: Int32
The size of the input buffer in bytes (roughly the maximum amount of memory that will be allocated for the outbound packets).
var supportedProtocols: PackedStringArray
The WebSocket sub-protocols allowed during the WebSocket handshake.
func acceptStream(StreamPeer?
) -> GodotError Accepts a peer connection performing the HTTP handshake as a WebSocket server. The
stream
must be a valid TCP stream retrieved viatakeConnection
, or a TLS stream accepted viaacceptStream(_:serverOptions:)
.func close(code: Int32, reason: String
) Closes this WebSocket connection.
code
is the status code for the closure (see RFC 6455 section 7.4 for a list of valid status codes).reason
is the human readable reason for closing the connection (can be any UTF-8 string that’s smaller than 123 bytes). Ifcode
is negative, the connection will be closed immediately without notifying the remote peer.func connectToUrl(String, tlsClientOptions: TLSOptions?
) -> GodotError Connects to the given URL. TLS certificates will be verified against the hostname when connecting using the
wss://
protocol. You can pass the optionaltlsClientOptions
parameter to customize the trusted certification authorities, or disable the common name verification. Seeclient(trustedChain:commonNameOverride:)
andclientUnsafe(trustedChain:)
.func getCloseCode(
) -> Int32 Returns the received WebSocket close frame status code, or
-1
when the connection was not cleanly closed. Only call this method whengetReadyState
returns .closed.func getCloseReason(
) -> String Returns the received WebSocket close frame status reason string. Only call this method when
getReadyState
returns .closed.func getConnectedHost(
) -> String Returns the IP address of the connected peer.
func getConnectedPort(
) -> UInt16 Returns the remote port of the connected peer.
func getCurrentOutboundBufferedAmount(
) -> Int32 Returns the current amount of data in the outbound websocket buffer. > Note: Web exports use WebSocket.bufferedAmount, while other platforms use an internal buffer.
func getReadyState(
) -> WebSocketPeer.State Returns the ready state of the connection. See
State
.func getRequestedUrl(
) -> String Returns the URL requested by this peer. The URL is derived from the
url
passed toconnectToUrl(_:tlsClientOptions:)
or from the HTTP headers when acting as server (i.e. when usingacceptStream(_:)
).func getSelectedProtocol(
) -> String Returns the selected WebSocket sub-protocol for this connection or an empty string if the sub-protocol has not been selected yet.
func poll(
) Updates the connection state and receive incoming packets. Call this function regularly to keep it in a clean state.
func send(message: PackedByteArray, writeMode: WebSocketPeer.WriteMode
) -> GodotError Sends the given
message
using the desiredwriteMode
. When sending aString
, prefer usingsendText(message:)
.func sendText(message: String
) -> GodotError Sends the given
message
using WebSocket text mode. Prefer this method overputPacket(buffer:)
when interacting with third-party text-based API (e.g. when usingJSON
formatted messages).func setNoDelay(enabled: Bool
) Disable Nagle’s algorithm on the underling TCP socket (default). See
setNoDelay(enabled:)
for more information.func wasStringPacket(
) -> Bool Returns
true
if the last received packet was sent as a text payload. SeeWriteMode
.
Citizens in SwiftGodot
Conformances
protocol CaseIterable
A type that provides a collection of all of its values.
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol RawRepresentable<RawValue>
A type that can be converted to and from an associated raw value.
Type members
Instance members
var debugDescription: String
A textual representation of this instance, suitable for debugging
Type features
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.