Instance Methodmigueldeicaza.swiftgodot 0.45.0SwiftGodot
sendText(message:)
Sends the given message
using WebSocket text mode. Prefer this method over putPacket(buffer:)
when interacting with third-party text-based API (e.g. when using JSON
formatted messages).
final func sendText(message: String) -> GodotError
Other members in extension
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 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
.