Socket Swift Reference Documentation
CkoSocket
Current Version: 11.5.0
Chilkat.Socket
Connect to remote hosts and ports for custom protocols or direct
socket-level communication.
Use SSL/TLS, inspect certificates, provide client certificates, and
control TLS-related behavior when secure sockets are required.
Send and receive strings, byte data, files, fixed-size blocks,
delimiter-terminated messages, or protocol-specific data patterns.
Listen for and accept incoming client connections when implementing
simple socket servers or custom listener workflows.
Route socket connections through HTTP proxies, SOCKS proxies, or
SSH-tunneled connections when network topology requires it.
Configure connection and read/write timeouts, monitor counters, and use
logs and
For an extended overview, see
Socket Class Overview.
Build custom TCP, TLS, proxy, SSH-tunneled, client/server, and socket-level protocols.
Chilkat.Socket is the low-level networking class for
applications that need direct control over TCP and TLS communication. It can
connect as a client, accept incoming connections, send and receive text or
binary data, use proxies or SSH tunnels, configure TLS certificates and
socket options, manage timeouts, work with socket sets, collect performance
counters, and produce detailed diagnostics and session logs for custom
protocol troubleshooting.
TCP client connections
TLS and certificates
Send and receive data
Server-side sockets
Proxy and SSH tunneling
Timeouts and diagnostics
LastErrorText to diagnose connection or protocol
failures.
Socket when the application is implementing a custom
protocol or needs lower-level control than higher-level Chilkat classes
provide. Configure the connection, TLS, proxy, timeout, and logging options,
connect or accept a client, then send and receive data according to the
protocol. Use higher-level classes such as Http,
Rest, Ssh, SFtp, or
MailMan when the protocol is already directly supported.
Object Creation
let obj = CkoSocket()!
Properties
AbortCurrent
Set this property to true to request cancellation of the method currently executing on this object. It affects operations that can block or take significant time, such as network reads, writes, connection establishment, and long-running asynchronous methods. Fast, nonblocking methods may finish before the cancellation request is observed.
After an operation aborts, Chilkat automatically resets this property to false. If no operation is running, the next method call clears a previously set value before it begins.
LastErrorText describes the abort.AcceptFailReason
Contains the numeric result for the most recent AcceptNext or deprecated AcceptNextConnection operation. The initial value is 0. It is reset to 0 when an accept begins, remains 0 on success, and is set to a reason code on failure.
| Code | Meaning |
|---|---|
| 0 | Success. |
| 1 | An asynchronous accept operation is already in progress. |
| 3 | Internal failure, such as an allocation failure. |
| 5 | No incoming connection was accepted before the wait interval expired. |
| 6 | The operation was aborted by the application. |
| 9 | An unspecified fatal socket error occurred. |
| 20 | The socket has not first been bound and placed into listening mode. |
| 99 | The Chilkat component is not unlocked. |
| 100 | TLS internal error. |
| 102 | Unexpected TLS handshake message. |
| 109 | Failed to read TLS handshake messages. |
| 114 | Failed to send the ChangeCipherSpec message. |
| 115 | Failed to send the Finished message. |
| 116 | The client's Finished message was invalid. |
| 117 | Unable to agree on a TLS protocol version. |
| 118 | Unable to agree on a cipher suite. |
| 119 | Failed to read the client's ClientHello message. |
| 120 | Failed to send TLS handshake messages. |
| 121 | Failed to process the client certificate message. |
| 122 | Failed to process the client certificate URL message. |
| 123 | Failed to process the client key-exchange message. |
| 124 | Failed to process the CertificateVerify message. |
| 125 | An SSL 2.0 connection attempt was received and rejected. |
AlpnProtocol
Specifies the application-layer protocol name offered in the TLS ALPN extension, such as h2 or http/1.1. Leave it empty when ALPN is not required.
BandwidthThrottleDown
Limits receive throughput to approximately the specified number of bytes per second. The default value is 0, which disables receive throttling.
BandwidthThrottleUp
Limits send throughput to approximately the specified number of bytes per second. The default value is 0, which disables send throttling.
BigEndian
Controls the byte order used by SendCount and ReceiveCount. The default is true, which uses big-endian byte order (network byte order). Set it to false to use little-endian byte order.
SendInt16, SendInt32, ReceiveInt16, and ReceiveInt32 methods receive their byte-order choice as an argument.ClientIpAddress
Specifies a numeric local IP address to use when binding the socket to a local interface.
- Outbound connections: Before
Connectestablishes the connection, the local socket is bound to this address. Leave the property empty to let the operating system choose the local source address. - Listeners:
BindAndListenandBindAndListenPortRangebind to exactly this address. Leave the property empty to listen on all interfaces:0.0.0.0for IPv4 or::for IPv6.
ClientIpAddress | IPv6 preference | Listener bind address |
|---|---|---|
| Empty | false | 0.0.0.0 (all IPv4 interfaces) |
| Empty | true | :: (all IPv6 interfaces) |
| Explicit address | Not used to choose the family | Exactly the specified address |
127.0.0.1 or ::1 creates a loopback-only listener that remote computers cannot reach.ClientPort
Specifies the local TCP port to bind before initiating an outbound connection. The default value is 0, which asks the operating system to choose an available ephemeral port.
ConnectFailReason
Contains the numeric result for the most recent connect-family operation, including TCP connection and SSH connection/channel setup. The initial value is 0. It is reset to 0 when a connect-family call begins, remains 0 on success, and is set to a reason code on failure.
| Code | Meaning |
|---|---|
| 0 | Success. |
| 1 | The hostname is empty. |
| 2 | DNS lookup failed. |
| 3 | DNS lookup timed out. |
| 4 | The operation was aborted by the application. |
| 5 | Internal failure. |
| 6 | The TCP connection attempt timed out. |
| 7 | The connection was rejected or otherwise could not be established. |
| 100 | TLS internal error. |
| 101 | Failed to send ClientHello. |
| 102 | Unexpected TLS handshake message. |
| 103 | Failed to read ServerHello. |
| 104 | The server did not provide a certificate. |
| 105 | Unexpected TLS protocol version. |
| 106 | Server-certificate verification failed. |
| 107 | The negotiated TLS protocol version was not permitted. |
| 108 | An application-defined server-certificate requirement failed. |
| 109 | Failed to read TLS handshake messages. |
| 110 | Failed to send the client-certificate message. |
| 111 | Failed to send the client key-exchange message. |
| 112 | The client certificate's private key was not accessible. |
| 113 | Failed to send the client CertificateVerify message. |
| 114 | Failed to send the ChangeCipherSpec message. |
| 115 | Failed to send the Finished message. |
| 116 | The server's Finished message was invalid. |
Connect is distinct from DNS, proxy, and TLS-handshake inactivity limits. See MaxReadIdleMs and MaxSendIdleMs.DebugLogFilePath
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
ElapsedSeconds
Returns the whole number of seconds elapsed since the most recent call to StartTiming. It returns 0 if timing has not been started or less than one second has elapsed.
HeartbeatMs
Specifies the interval, in milliseconds, between AbortCheck callbacks during supported long-running operations. The default is 0, which disables periodic AbortCheck callbacks.
HttpProxyAuthMethod
Specifies the authentication method used with an HTTP proxy. Supported values are Basic and NTLM. Leave it empty when the proxy does not require authentication.
HttpProxyDomain
Specifies the optional Windows domain used for NTLM authentication to an HTTP proxy. It is ignored unless HttpProxyAuthMethod is NTLM.
HttpProxyForHttp
Set this property to true when the proxied connection will carry HTTP requests, such as when a Rest object uses this socket through UseConnection. The default is false.
An HTTP client can communicate with a proxy differently from a non-HTTP protocol. For example, plain HTTP commonly sends an absolute request URI to the proxy, whereas other protocols generally require an HTTP CONNECT tunnel.
HttpProxyHostname
Specifies the hostname or numeric IP address of the HTTP proxy. Leave it empty to connect directly without an HTTP proxy.
topHttpProxyPassword
Specifies the password used to authenticate with the HTTP proxy. It is used together with HttpProxyUsername and the selected HttpProxyAuthMethod.
HttpProxyPort
Specifies the TCP port of the HTTP proxy. Common values include 8080 and 3128, but the correct port is determined by the proxy configuration.
HttpProxyUsername
Specifies the username used to authenticate with the HTTP proxy. It is ignored when the proxy does not require authentication.
topIsConnected
Returns true when the socket is in its last known connected state; otherwise returns false. Explicitly closing the socket updates this property immediately.
true until a read, write, or other socket operation detects the loss. Treat it as a cached state indicator, not a guarantee that the next operation will succeed.KeepAlive
Controls the operating system SO_KEEPALIVE option for the underlying TCP socket. The default is true.
KeepSessionLog
Set this property to true to record bytes sent and received through this wrapper in SessionLog. The default is false. Use SessionLogEncoding to choose how bytes are rendered.
LastErrorHtml
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodFailed
Returns true if the most recent action method called through this wrapper failed; otherwise returns false. The initial value is false. An action method clears this state when it begins and leaves it false on success or sets it to true on failure.
Ordinary value-property getters, such as the local and remote address/port properties, timeout properties, Ssl, BigEndian, and the failure-reason properties, do not change this state. Methods that perform work do change it, including certificate-retrieval methods, BuildHttpGetRequest, and ClearSessionLog.
LastMethodSuccess
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
ListenPort
Returns the port on which the socket is listening. This is especially useful after calling BindAndListen with port 0, which asks the operating system to select an available port.
LocalIpAddress
Returns the local numeric IP address for the socket connection currently held by this object. For an outbound connection, this is the source address selected or explicitly bound. For a listener, it is the address on which the socket is listening.
Returns an empty string when the object holds no connection or listener. The value is read from the current connection and is never retained from an earlier connection.
topLocalPort
Returns the local TCP port for the socket connection or listener currently held by this object. When binding to port 0, read this property or ListenPort after success to discover the operating-system-selected port.
Returns 0 when the object holds no connection or listener. The value is read from the current connection and is never retained from an earlier connection.
MaxReadIdleMs
Specifies the maximum number of milliseconds that a read-related operation may make no receive progress. A positive value is an inactivity timeout, not a total-operation deadline. The timer restarts each time a successful low-level read transfers at least one byte.
0means no read-idle timeout and permits an indefinite wait.- A positive value limits the longest continuous period with no received data.
- Negative values have no defined meaning and should not be used.
This property applies to socket receive methods and to protocol exchanges that read from the connection, including TLS handshakes. It also ordinarily governs read inactivity during HTTP/SOCKS proxy negotiation and SSH tunnel setup when no separate timeout is provided.
0. For operations involving an externally
controlled peer, proxy, TLS handshake, or SSH service, consider setting a
finite value so an unresponsive endpoint cannot block the operation forever.
MaxSendIdleMs
Specifies the maximum number of milliseconds that a send-related operation may make no write progress. A positive value is an inactivity timeout, not a total-operation deadline. The timer restarts each time a successful low-level write transfers at least one byte.
0means no send-idle timeout and permits an indefinite wait.- A positive value limits the longest continuous period with no send progress.
- Negative values have no defined meaning and should not be used.
This property applies to socket send methods and to protocol exchanges that write to the connection, including TLS handshakes. It also ordinarily governs write inactivity during HTTP/SOCKS proxy negotiation and SSH tunnel setup when no separate timeout is provided.
MyIpAddress
Returns a local IP address for the computer. On a multihomed system, this is a default or preferred local address and may not be the address used by a particular connection.
LocalIpAddress and LocalPort.NumBytesAvailable
Returns the number of bytes immediately available to the socket layer without waiting. On a TLS connection, the value can include encrypted TLS record overhead and therefore does not necessarily equal the amount of application plaintext available.
NumReceivedClientCerts
Returns the number of client certificates associated with the connection currently held by this object. On a TLS server, read this property on the accepted connection populated by AcceptNext, then call GetRcvdClientCert with indexes from 0 through NumReceivedClientCerts - 1.
Returns 0 when the current connection has no received client certificates or when the object holds no connection. The value is read from the current connection and is never retained from an earlier connection. If ConvertFromSsl removes TLS while preserving the underlying connection, the certificate information can remain associated with that same connection.
NumSocketsInSet
Returns the number of sockets contained in this object's socket set. A normal Socket object becomes a socket set after one or more successful calls to TakeSocket. Listener sockets and connected sockets may coexist in the same set.
A socket whose peer has closed may remain in the set, and remain included in this count, until the next SelectForReading or SelectForWriting. A select operation rebuilds the set and automatically prunes members that no longer have a usable descriptor.
SelectorIndex for a direct set position. After a select call, use SelectorReadIndex or SelectorWriteIndex directly; do not translate the ready index into SelectorIndex.NumSslAcceptableClientCAs
Returns the number of acceptable certificate-authority distinguished names supplied by the TLS server for the connection currently held by this object. Use GetSslAcceptableClientCaDn to retrieve each DN by zero-based index.
Returns 0 when the current connection supplied no acceptable-CA list or when the object holds no connection. This value is read from the current connection and is never retained from an earlier connection.
ObjectId
Returns the unique identifier assigned to this socket object. The identifier is included in event callbacks so an application can associate a callback with the originating object.
PercentDoneScale
Defines the numeric value that represents 100 percent in PercentDone callbacks. The default is 100. For example, a scale of 1000 permits tenths-of-a-percent values, so 453 represents 45.3 percent.
Values are clamped to the range 10 through 100000. The property affects only operations whose progress can be measured and only language bindings that expose callbacks.
PreferIpv6
This property and ListenIpv6 are two names for the same underlying setting. Reading or writing either property reads or changes the same value. The default is false.
- Outbound connections: When a hostname resolves to both IPv4 and IPv6 addresses,
falseprefers IPv4 andtrueprefers IPv6. - Listeners: When
ClientIpAddressis empty,falsebinds to0.0.0.0andtruebinds to::. When an explicitClientIpAddressis set, its literal address determines the family.
RcvBytesPerSec
Returns the average raw receive rate, in bytes per second, since receive performance measurement began or was last reset. The measurement includes TLS or SSH framing overhead. Call ResetPerf with true to restart receive measurement.
ReceivedCount
Tracks the cumulative number of application bytes actually received from the connection by receive operations. The application may assign 0 at any time to restart the count.
Bytes pulled from the connection remain included even when the receive method ultimately returns failure. A failed call does not roll the counter back. For example, partial bytes consumed before a timeout, abort, close, or reset are still counted, even when the method does not return those bytes to the caller.
The count can be greater than the number of bytes returned by a particular method because Chilkat may read beyond a delimiter or exact requested length and buffer the excess for a later receive call. TLS and SSH framing overhead is not included.
RcvBytesPerSec when measuring raw transfer rate including protocol overhead.ReceivedInt
Contains the value produced by the most recent successful call through this wrapper to ReceiveByte, ReceiveInt16, or ReceiveInt32. The initial value is 0. The signedness and byte order are determined by the arguments supplied to the receive method.
This property is never cleared automatically. It changes only after a successful integer receive or when the application explicitly assigns a value to it. A failed integer receive leaves the previous value unchanged.
ReceivedInt only after the corresponding receive method has returned success. After a failed call it may still contain a valid-looking value from an earlier operation.ReceiveFailReason
Contains the numeric result for the most recent receive-side operation. The initial value is 0. It is reset to 0 when a receive begins, remains 0 on success, and is set to a reason code on failure.
| Code | Meaning |
|---|---|
| 0 | Success. |
| 1 | An asynchronous receive operation is already in progress. |
| 2 | The socket is not connected. |
| 3 | Internal failure, such as an allocation failure. |
| 4 | Invalid parameters were supplied. For delimiter-based receives, this includes an empty match string or a match string that encodes to zero bytes. |
| 5 | No additional data arrived within MaxReadIdleMs. |
| 6 | The operation was aborted by the application. |
| 7 | The peer reset the connection. |
| 8 | The host operating system aborted the established connection. |
| 9 | An unspecified fatal socket error occurred. |
| 10 | The peer closed the connection normally. The method reports failure, but its output may still contain final data received immediately before the close. |
ReceivedCount. Depending on the receive method, partial data may
be returned, appended to the destination, or discarded. Consult the specific
method description.
Socket object may still be closed or reused for a new
Connect operation.
ReceivePacketSize
Controls the maximum number of bytes requested by availability-based receive
methods when Chilkat must perform a direct read from a plain TCP connection.
The default value is 4096.
-
For plain TCP, methods such as
ReceiveBytes,ReceiveBd,ReceiveString, andReceiveSbobtain at most this many bytes from one underlying socket read. - For TLS and SSH connections, the amount returned is governed by the TLS record or SSH packet and is not limited by this property.
-
Data already buffered internally by Chilkat is returned in full, even when
it exceeds
ReceivePacketSize.
RemoteIpAddress
Returns the numeric IP address of the peer for the connection currently held by this object. This is the address actually used by the established connection, which may differ from the hostname originally supplied to Connect.
Returns an empty string when the object holds no connected peer. The value is read from the current connection and is never retained from an earlier connection.
topRemotePort
Returns the TCP port of the peer for the connection currently held by this object.
Returns 0 when the object holds no connected peer. The value is read from the current connection and is never retained from an earlier connection.
RequireSslCertVerify
Controls verification of a server certificate when this object acts as a TLS client. The default is false.
When true, the TLS connection is rejected if the server certificate is expired, not yet valid, has an invalid signature, or cannot be verified through a trusted certificate chain. When false, these normal certificate-validity and trust-chain checks are not required.
RequireSslCertVerify controls normal certificate verification. Public-key pinning configured by TlsPinSet is a separate check and is enforced whenever a pin set is present, even when this property is false.SelectorIndex
Selects a socket by its direct zero-based position in this object's socket set. Valid values range from 0 through NumSocketsInSet - 1. While this selector is active, ordinary connection methods and properties are routed to that contained socket.
SelectorIndex, SelectorReadIndex, and SelectorWriteIndex are mutually exclusive. Assigning any one clears the other two. Do not copy a read-ready or write-ready index into SelectorIndex; setting SelectorReadIndex or SelectorWriteIndex already routes operations to the corresponding ready socket.SelectorIndex can identify a different socket or become out of range.SelectorReadIndex
Selects a zero-based position in the read-ready result produced by the most recent call to SelectForReading. If that call returned n, valid values are 0 through n - 1. After assigning this property, call AcceptNext, a receive method, or another ordinary connection operation on this socket-set object; the operation is routed directly to that ready socket.
Reading this property returns exactly the ready-set position last assigned. It does not return or translate to the socket's direct position in the contained set, and no such translation is required.
SelectorReadIndex clears SelectorIndex and SelectorWriteIndex. Do not set SelectorIndex afterward, because doing so discards the read selection and interprets the number as a direct set position.SelectForReading or SelectForWriting invalidates prior ready indices.SelectorWriteIndex
Selects a zero-based position in the write-ready result produced by the most recent call to SelectForWriting. If that call returned n, valid values are 0 through n - 1. After assigning this property, ordinary connection operations on this socket-set object are routed directly to that ready socket.
Reading this property returns exactly the ready-set position last assigned. It does not return or translate to the socket's direct position in the contained set.
SelectorWriteIndex clears SelectorIndex and SelectorReadIndex. Do not set SelectorIndex afterward.SendBytesPerSec
Returns the average raw send rate, in bytes per second, since send performance measurement began or was last reset. The measurement includes TLS or SSH framing overhead. Call ResetPerf with false to restart send measurement.
SendFailReason
Contains the numeric result for the most recent send-side operation. The initial value is 0. It is reset to 0 when a send begins, remains 0 on success, and is set to a reason code on failure.
| Code | Meaning |
|---|---|
| 0 | Success. |
| 1 | An asynchronous send operation is already in progress. |
| 2 | The socket is not connected. |
| 3 | Internal failure, such as an allocation failure. |
| 4 | Invalid parameters were supplied. |
| 5 | The socket made no send progress for longer than MaxSendIdleMs. |
| 6 | The operation was aborted by the application. |
| 7 | The peer reset the connection. |
| 8 | The host operating system aborted the established connection. |
| 9 | An unspecified fatal socket error occurred. |
| 10 | The peer closed the connection. |
| 11 | Text or encoded input could not be converted or decoded, such as an invalid StringCharset conversion or malformed encoded data. |
SendPacketSize
Specifies the internal chunk size used when sending a large amount of data over a plain TCP connection. The default is 65535 bytes. TLS connections use TLS record handling rather than this setting.
SessionLog
Returns the accumulated send/receive session log for this wrapper when KeepSessionLog is true. Use SessionLogEncoding to choose an escaped or hexadecimal representation and ClearSessionLog to reset it.
SessionLogEncoding
Controls how bytes are rendered in SessionLog. The default is esc.
| Value | Format |
|---|---|
esc | Compact C-style escaped text. Printable ASCII remains readable; control and nonprintable bytes are escaped, such as \r, \n, and \xHH. |
hex | Every byte is represented in hexadecimal, which is larger but unambiguous for binary protocols. |
SniHostname
Sets the Server Name Indication (SNI) hostname sent in the TLS ClientHello. By default, Chilkat uses the hostname passed to Connect. Set this property when connecting to a numeric IP address or alternate network endpoint while the TLS server expects a particular virtual-host name.
SocksHostname
Specifies the hostname or numeric IP address of the SOCKS proxy. It is used only when SocksVersion is 4 or 5.
SocksPassword
Specifies the password for SOCKS5 username/password authentication. SOCKS4 does not define a password field, so this property is ignored for SOCKS4.
SocksPort
Specifies the TCP port of the SOCKS proxy. The default is 1080. It is used only when SocksVersion is 4 or 5.
SocksUsername
Specifies the SOCKS proxy username. For SOCKS4 it is the user ID sent in the request; for SOCKS5 it is used when username/password authentication is negotiated.
topSocksVersion
Selects whether connections are routed through a SOCKS proxy.
| Value | Behavior |
|---|---|
| 0 | Do not use a SOCKS proxy. This is the default. |
| 4 | Connect through a SOCKS4 proxy. |
| 5 | Connect through a SOCKS5 proxy. |
SoRcvBuf
Requests the operating-system receive-buffer size for the TCP socket. The default requested value is 4194304 bytes. Most applications should leave it unchanged.
SoReuseAddr
Controls the SO_REUSEADDR option for a socket that will bind and listen. The default is true. Set it before BindAndListen, BindAndListenPortRange, or InitSslServer.
SO_REUSEADDR differs across operating systems. It can help restart a listener after a previous connection, but it is not a portable substitute for exclusive-port ownership.SoSndBuf
Requests the operating-system send-buffer size for the TCP socket. The default requested value is 262144 bytes. Most applications should leave it unchanged.
Ssl
Controls whether incoming connections accepted by this listener must complete a TLS handshake. The default is false. Set it to true for a TLS server listener.
InitSslServer before accepting TLS clients. Do not use TlsVersion or TlsCipherSuite alone to determine whether the current connection is protected by TLS, because those properties retain the results of the object's most recent successful TLS handshake even after the connection changes.SslAllowedCiphers
Restricts the cipher suites permitted for TLS connections. This property has the same behavior as Chilkat.Http.SslAllowedCiphers and applies to TLS client connections and TLS server handshakes.
The default empty string allows all cipher suites implemented and enabled by the Chilkat build. To restrict negotiation, provide a comma-separated list of cipher-suite names in preference order, for example:
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
The negotiated suite must be in the intersection supported by both peers. A TLS client supplies its allowed list to the server; the server ultimately chooses from that list.
The following policy keywords are also recognized:
rsa1024— when acting as a client, reject a server certificate whose RSA key is smaller than 1024 bits.rsa2048— when acting as a client, reject a server certificate whose RSA key is smaller than 2048 bits.secure-renegotiation— require secure renegotiation.best-practices— use Chilkat's current best-practices policy. The exact policy may change in later Chilkat versions.
Legacy filter keywords such as aes256-cbc, aes128-cbc, 3des-cbc, and rc4 remain recognized for compatibility.
best-practices can change with Chilkat versions and platform capabilities.SslProtocol
Selects the SSL/TLS protocol version allowed for secure connections. This property has the same behavior as Chilkat.Http.SslProtocol and applies to TLS client connections and TLS server handshakes.
Accepted values are:
defaultTLS 1.3TLS 1.2TLS 1.1TLS 1.0SSL 3.0TLS 1.3 or higherTLS 1.2 or higherTLS 1.1 or higherTLS 1.0 or higher
The default value is default, which allows the protocol to be selected dynamically according to what the peer and Chilkat support. Choosing an exact version causes the connection to fail unless that exact version is negotiated. A minimum-version form such as TLS 1.2 or higher is generally preferable to an exact version.
StringCharset
Specifies the character encoding used by text-oriented socket methods. Examples include utf-8, windows-1252, shift_jis, and iso-8859-1. The default is ansi.
The value ansi means the system default encoding determined by the default system locale. It is not a fixed encoding such as Windows-1252, ISO-8859-1, or ASCII; the actual encoding is platform- and system-configuration-dependent.
Sending methods such as SendString and SendSb encode text using this charset. String receive methods decode incoming bytes from this charset, including ReceiveString, ReceiveSb, ReceiveToCRLF, and delimiter-based string methods.
utf-8 rather than ansi. Use byte-oriented methods when the protocol is binary or exact byte preservation is required.TcpNoDelay
Controls the TCP_NODELAY option. The default is false, allowing the Nagle algorithm. Set it to true to send small writes with lower latency rather than waiting to coalesce them.
TlsCipherSuite
Returns the cipher suite from the most recent successful TLS handshake performed by this Socket object, for example TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384. It is empty until the object has completed its first successful TLS handshake.
Close, a failed connection attempt, a later plain-TCP connection, and ConvertFromSsl. It is replaced only when this object completes another successful TLS handshake. Do not use this property alone to determine whether the current connection is protected by TLS.
TlsPinSet
Specifies one or more expected SubjectPublicKeyInfo (SPKI) fingerprints for TLS public-key pinning. If the certificate presented by the server does not match any configured fingerprint, the TLS handshake is aborted and the connection fails.
The format is:
hash_algorithm, encoding, fingerprint1, fingerprint2, ...
For example, a single SHA-256 base64 pin is:
sha256, base64, lKg1SIqyhPSK19tlPbjl8s02yChsVTDklQpkMCHvsTE=
Supported hash algorithms include sha1, sha256, sha384, sha512, md2, md5, haval, ripemd128, ripemd160, ripemd256, and ripemd320. Supported encodings include base64, hex, and other Chilkat-supported binary encodings.
RequireSslCertVerify is false. Normal certificate validity and trust-chain verification remain separately controlled by RequireSslCertVerify.TlsVersion
Returns the protocol version from the most recent successful TLS handshake performed by this Socket object, such as TLS 1.2 or TLS 1.3. It is empty until the object has completed its first successful TLS handshake.
Close, a failed connection attempt, a later plain-TCP connection, and ConvertFromSsl. It is replaced only when this object completes another successful TLS handshake. Do not use this property alone to determine whether the current connection is protected by TLS.
UncommonOptions
Provides comma-separated compatibility or platform-specific options. The default is the empty string and should normally remain unchanged.
| Keyword | Behavior |
|---|---|
ProtectFromVpn | On Android, attempts to route the socket outside an active VPN. |
EnableTls13 | Historical compatibility option introduced when TLS 1.3 was not yet enabled by default. It is generally unnecessary in current versions. |
UserData
Stores arbitrary application text with the socket object. Chilkat does not transmit, interpret, or otherwise use this value. It is useful for associating a label, connection ID, or other application metadata with a socket.
topVerboseLogging
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
Methods
AcceptNext
Waits for and accepts the next incoming connection on a socket previously configured by BindAndListen or BindAndListenPortRange. For a TLS listener, acceptance includes the server-side TLS handshake.
maxWaitMs = 0waits indefinitely for an incoming connection.- A positive value waits up to that many milliseconds.
- Negative values have no defined meaning and should not be used.
socket; a prior call to Close is not required. The destination keeps its existing property values, while only its connection is replaced. If the destination is actively performing another operation, the accept fails rather than interrupting that operation.socket is left completely unchanged. The listening socket also remains active after a timeout or a per-client TLS failure, so the application may immediately call AcceptNext again without rebinding.The accepted connection is independent of the listener and all other accepted connections. Listener properties are not copied to the accepted socket. Configure the destination before or after a successful accept as needed.
| Setting | Inherited from listener? |
|---|---|
MaxReadIdleMs / MaxSendIdleMs | No |
| Verbose logging and debug-log path | No |
| Upload/download bandwidth throttling | No |
| Socket buffers and TCP no-delay options | No |
SslAllowedCiphers / SslProtocol | No |
InitSslServer remains on the listener and is used for each handshake. The accepted socket contains that connection's negotiated TLS state, peer information, and any received client certificate. Examine those values on the accepted socket.maxWaitMs governs the wait for the incoming TCP connection. Handshake inactivity is governed by MaxReadIdleMs and MaxSendIdleMs on the listener.Returns true for success, false for failure.
AcceptNextAsync (1)
Creates an asynchronous task to call the AcceptNext method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
AddSslAcceptableClientCaDn
Adds a certificate-authority distinguished name to the list advertised by a TLS server when requesting a client certificate for mutual TLS. Call this method once for each acceptable CA distinguished name.
AddSslAcceptableClientCaDn before InitSslServer. The acceptable-CA list is captured when InitSslServer creates the TLS server configuration. Names added afterward are not included in that configuration's CertificateRequest and therefore do not affect its handshakes.Skip this method when the server does not request client certificates. If no CA distinguished names are added, client certificates issued by any root CA are accepted by this CA-name filter.
AcceptNext succeeds, inspect the client certificates on the accepted socket and apply the application's authorization policy.Returns true for success, false for failure.
BindAndListen
Binds a TCP listener to port and places it into listening mode. After this method succeeds, call AcceptNext to accept incoming connections.
When ClientIpAddress is empty, the listener binds to all interfaces: 0.0.0.0 when the shared ListenIpv6/PreferIpv6 setting is false, or :: when it is true. To restrict the listener to one local interface, set ClientIpAddress to that interface's numeric address before calling this method. The explicit address also determines whether the listener is IPv4 or IPv6.
backLog is the requested operating-system queue length for connections that have completed or are completing the TCP handshake but have not yet been accepted. It is a queue hint, not a limit on the total number of clients the application can serve.
Pass 0 for port to let the operating system choose an available port, then read ListenPort.
ClientIpAddress binds to all interfaces, remote computers can connect by default, subject to routing and firewall rules. Set ClientIpAddress to 127.0.0.1 or ::1 for a loopback-only listener.Close is not required. If another operation is actively using the socket, this call fails with an in-use error.AddSslAcceptableClientCaDn first. Then call InitSslServer, BindAndListen, and AcceptNext, in that order. Calling InitSslServer after binding discards the listener and leaves the object unbound.Returns true for success, false for failure.
BindAndListenAsync (1)
Creates an asynchronous task to call the BindAndListen method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
BindAndListenPortRange
Searches the inclusive range beginPort through endPort for an available TCP port, binds it, and begins listening. The method returns the selected port, or -1 when no port can be bound or another error occurs.
When ClientIpAddress is empty, the listener binds to all interfaces: 0.0.0.0 when the shared ListenIpv6/PreferIpv6 setting is false, or :: when it is true. Set ClientIpAddress to a numeric local address to bind only to that interface; the explicit address determines the address family.
backLog is the requested operating-system pending-connection queue length. The operating system may cap or adjust it.
AcceptNext to accept incoming connections. For TLS listeners, complete AddSslAcceptableClientCaDn, if needed, and InitSslServer before calling this method.BindAndListenPortRangeAsync (1)
Creates an asynchronous task to call the BindAndListenPortRange method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
BuildHttpGetRequest
Builds and returns a simple HTTP GET request for url. The method only constructs the request text; it does not connect, send the request, follow redirects, or read a response.
Http or Rest class for normal HTTP work. This helper is intended for low-level socket examples or custom HTTP handling.Returns nil on failure
CheckWriteable
Waits for the connected socket to become writable.
maxWaitMs = 0performs a nonblocking poll and returns immediately.- A positive value waits up to that many milliseconds.
- Negative values have no defined meaning and should not be used.
| Return value | Meaning |
|---|---|
| 1 | The socket is connected and currently writable. |
| 0 | The socket was not writable before the timeout, or the operation was aborted. |
| -1 | The socket is not connected or an error occurred. |
CheckWriteableAsync (1)
Creates an asynchronous task to call the CheckWriteable method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ClearSessionLog
Clears the accumulated text returned by SessionLog for this wrapper. It does not change KeepSessionLog or close the connection.
Close
Attempts to gracefully terminate and close the current TCP, TLS, or SSH channel connection. maxWaitMs controls how long the method waits for clean shutdown processing.
0waits indefinitely for the clean close.- A positive value waits up to that many milliseconds.
- Negative values have no defined meaning and should not be used.
The method is safe and idempotent. Calling it on an already closed or never-connected object does nothing and returns true. Repeated calls are harmless; the diagnostic log may note that there was no connection to close.
Close is routed to the selected member, closes it, and removes it from the set immediately. There is no separate remove-without-closing method. Direct SelectorIndex positions after the removed member shift down.DupSocket, calling Close on any wrapper closes the connection for all wrappers. Merely destroying one duplicate without calling Close releases only that wrapper's reference.IsConnected is false for the closed connection. A graceful transport close cannot guarantee that the remote application processed all data sent before the close.Returns true for success, false for failure.
CloseAsync (1)
Creates an asynchronous task to call the Close method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
Connect
Establishes a TCP connection to hostname:port. Set
ssl to true to perform a TLS handshake after the TCP connection
succeeds; set it to false for plain TCP. hostname may be a DNS
name or a numeric IPv4 or IPv6 address.
maxWaitMs is the overall wait budget for DNS resolution performed
by this call and establishment of the TCP connection. Its special values are:
0waits indefinitely, subject to an internal effective ceiling of approximately six hours.- A positive value below
100milliseconds is treated as100milliseconds. - Negative values have no defined meaning and should not be used.
The later TLS handshake is governed by MaxReadIdleMs and
MaxSendIdleMs, not by maxWaitMs. HTTP and SOCKS proxy
protocol exchanges ordinarily use those read/write idle timeouts as well;
there is no separate proxy-negotiation timeout property.
Connection options such as ClientIpAddress,
ClientPort, proxy settings, PreferIpv6, TLS policy,
SNI, ALPN, certificate verification, pinning, and client certificates must be
configured before calling this method.
| Connection phase | Timeout |
|---|---|
DNS resolution performed by Connect | maxWaitMs overall budget |
| TCP connection establishment | maxWaitMs |
| TLS handshake | MaxReadIdleMs and MaxSendIdleMs |
| HTTP/SOCKS proxy exchanges | Ordinarily the read/write idle timeouts; no separate setting is provided |
Close is not required. If this object is already
connected, listening, or contains leftover state from a failed connection or
TLS upgrade, Connect discards that state and establishes the new
connection. An existing TCP or TLS connection is torn down immediately rather
than closed gracefully, and an existing listener is stopped. If another
operation is actively using the socket, the call fails with an in-use error
instead of interrupting that operation.
SelectorIndex, SelectorReadIndex, or
SelectorWriteIndex selects a member, this method is routed to that
selected member. With no active selector, it creates or replaces the set
container object's own direct connection and leaves the contained members
unchanged.
Returns true for success, false for failure.
ConnectAsync (1)
Creates an asynchronous task to call the Connect method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ConvertFromSsl
Ends the TLS layer while leaving the underlying TCP connection open for subsequent unencrypted communication. This is the reverse of a STARTTLS-style upgrade and is valid only when TLS is currently active.
If called on a connected plain TCP socket, the method returns false because
there is no TLS layer to remove. The plain connection remains unchanged.
Returns true for success, false for failure.
ConvertFromSslAsync (1)
Creates an asynchronous task to call the ConvertFromSsl method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ConvertToSsl
Upgrades an already connected plain TCP socket to TLS by performing a client-side TLS handshake over the existing connection.
ConvertToSsl on a connection that is already protected by
TLS is unsupported. The method checks that a connection exists but does not
define a second TLS-upgrade operation. Call it only for an established plain
connection.
Returns true for success, false for failure.
ConvertToSslAsync (1)
Creates an asynchronous task to call the ConvertToSsl method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
DnsCacheClear
Clears Chilkat's process-wide in-memory DNS cache. Subsequent hostname resolutions perform a new lookup as needed.
DnsLookup
Resolves hostname and returns one numeric IP address.
maxWaitMs = 0waits indefinitely.- A positive value waits up to that many milliseconds.
- Negative values have no defined meaning and should not be used.
PreferIpv6; it is not a complete DNS-record enumeration.
Returns nil on failure
DnsLookupAsync (1)
Creates an asynchronous task to call the DnsLookup method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
DupSocket
Populates dest with another Socket wrapper that shares this object's underlying connection. The destination first releases its reference to any connection it previously held. The shared connection object is reference-counted, but all wrappers operate on the same live connection and byte stream.
The reference count keeps the underlying connection object alive while wrappers still refer to it; it does not prevent an explicit Close from shutting down the connection. TLS state, TLS conversion state, and the internal receive/over-read buffer are shared. A TLS renegotiation, ConvertToSsl, or ConvertFromSsl through one wrapper changes the connection seen by every duplicate. Bytes buffered through one wrapper may be consumed by a receive through another.
| State, setting, or result | Scope after DupSocket |
|---|---|
| Underlying connection, byte stream, TLS session, TLS conversion state, and receive buffer | Shared by all duplicates. |
ReceivedCount | Shared connection-level counter. All duplicates report the same cumulative value, and resetting it through one wrapper resets the value seen by the others. |
SendBytesPerSec and RcvBytesPerSec | Shared connection-level measurements. Calling ResetPerf through one wrapper resets the selected measurement for every duplicate. |
KeepSessionLog, SessionLog, and session logging | Per wrapper. Enabling logging on one duplicate does not enable it on another. Each wrapper logs only traffic that passes through it, and reading or clearing one wrapper's log does not affect another wrapper's log. |
LastMethodFailed, AcceptFailReason, ReceiveFailReason, SendFailReason, and ReceivedInt | Per wrapper. An operation performed through one duplicate does not update these values on another duplicate. |
Close on any wrapper actively closes the shared connection for all wrappers. The other wrapper objects remain alive, but subsequent I/O through them fails because the shared connection is closed.
Close. This drops only that wrapper's reference and leaves the connection usable through the remaining duplicates. Call Close on any one wrapper only when the shared connection should end for everyone.Returns true for success, false for failure.
GetAdaptersAddresses
Populates json with information about local network adapters, including IPv4 addresses, IPv6 addresses, and MAC addresses. Existing contents of the destination JSON object are replaced or populated according to the returned structure.
Returns true for success, false for failure.
GetLastJsonData
Copies additional JSON details from the most recently called method into json, when that method produced such information. Many methods produce an empty result.
GetMyServerCert
Copies the TLS server certificate configured by InitSslServer into cert. This method is intended for a socket acting as a TLS server and returns false when no server certificate has been configured.
Returns true for success, false for failure.
GetRcvdClientCert
Copies the client certificate at zero-based index into cert from the TLS handshake of an accepted server-side connection. Use NumReceivedClientCerts to determine the valid index range.
Client certificates are normally supplied only when the server requests mutual TLS authentication. The application can inspect the returned certificate and close the connection when it does not satisfy authorization requirements.
AcceptNext, not on the listener socket.Returns true for success, false for failure.
GetServerCert
Copies the certificate presented by the remote TLS server into cert for the current client-side TLS connection. The method returns false when the socket is not connected, is not using TLS, or no server certificate is available.
RequireSslCertVerify and/or TlsPinSet when validation is required.Returns true for success, false for failure.
GetSslAcceptableClientCaDn
Returns the certificate-authority distinguished name at zero-based index from the list sent by a TLS server when it requests a client certificate. Valid indexes range from 0 through NumSslAcceptableClientCAs - 1.
Returns nil on failure
InitSslServer
Configures this object for server-side TLS using cert as the server certificate. The certificate must have access to its corresponding private key.
For a TLS listener that requests client certificates, the required sequence is:
AddSslAcceptableClientCaDn (once for each acceptable CA) InitSslServer BindAndListen AcceptNext
For a TLS listener without client-certificate requests, omit AddSslAcceptableClientCaDn. For a plain non-TLS listener, omit both TLS setup steps.
When the object is not already connected, this method also sets Ssl to true. It may also be used on an already connected socket to begin server-side TLS on that live connection.
InitSslServer after BindAndListen. A listening socket is not treated as a connected socket, so this method replaces it with a new, unbound TLS-server socket and the existing bind is lost. All calls to AddSslAcceptableClientCaDn must also occur before this method.Returns true for success, false for failure.
LoadTaskCaller
Loads this object with the state of the object that initiated the asynchronous operation represented by task. This is useful when the task has completed on a worker thread and the caller state must be recovered into another wrapper object.
Socket asynchronous method and call this after completion.Returns true for success, false for failure.
topLoadTaskResult
Loads this socket object with the result state produced by a completed asynchronous task whose result is a socket. Call it only after the task has completed successfully.
LastErrorText when loading fails.Returns true for success, false for failure.
topPollDataAvailable
Performs a nonblocking check for readable activity on the socket. It returns true when data or another read-ready condition is present and false when nothing is immediately available.
PollDataAvailableAsync (1)
Creates an asynchronous task to call the PollDataAvailable method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveBd
Receives one delivery of binary data and appends it to binData.
Chilkat first appends any data already buffered internally. If no buffered
data exists, the method performs one receive operation; it does not loop to
drain everything that may be available.
-
For plain TCP, a direct read obtains at most
ReceivePacketSizebytes. -
For TLS or SSH, the amount is governed by the TLS record or SSH packet and
is not limited by
ReceivePacketSize. -
Already-buffered data is appended in full, even if it exceeds
ReceivePacketSize. - A successful call can append zero bytes during TLS renegotiation. Treat this as no application data yet and call the receive method again.
ReceiveFailReason = 10, but
binData may contain final bytes received immediately before the
close.
Returns true for success, false for failure.
ReceiveBdAsync (1)
Creates an asynchronous task to call the ReceiveBd method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveBdN
Receives exactly numBytes bytes and appends them to
binData. The method continues receiving until the requested count
is satisfied or a receive failure occurs. Inactivity is controlled by
MaxReadIdleMs.
false,
but the partial bytes remain appended to binData. Those bytes have
been consumed from the connection, are included in ReceivedCount,
and are not retained internally for a later receive call.
A timeout or application abort generally leaves the connection open. A peer close or reset leaves it unavailable for further I/O. When the requested count is successfully completed, bytes read beyond that count may remain buffered internally for the next receive operation.
Returns true for success, false for failure.
ReceiveBdNAsync (1)
Creates an asynchronous task to call the ReceiveBdN method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveByte
Reads exactly one byte from the connection and stores its numeric value in ReceivedInt. If bUnsigned is true, the result is in the range 0 through 255; otherwise it is interpreted as a signed two's-complement byte in the range -128 through 127.
The method waits according to MaxReadIdleMs and returns false on timeout, closure, or another receive failure. On failure, ReceivedInt is not cleared or changed; it retains the value from the last successful integer receive.
ReceivedInt contains a newly received byte.Returns true for success, false for failure.
ReceiveByteAsync (1)
Creates an asynchronous task to call the ReceiveByte method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveBytes
Receives binary data and returns one delivery of bytes. Chilkat first returns any data already buffered internally. If no buffered data exists, the method performs one receive operation; it does not loop to drain everything that may be available.
-
For plain TCP, a direct read returns at most
ReceivePacketSizebytes. -
For TLS or SSH, the returned amount is governed by the TLS record or SSH
packet rather than
ReceivePacketSize. -
Already-buffered data is returned in full, even if it exceeds
ReceivePacketSize. - A successful call can return zero bytes during TLS renegotiation. Treat this as no application data yet and call the receive method again.
ReceiveFailReason = 10, but the
returned byte data may contain final bytes received immediately before the
close. Process those bytes before finishing the receive loop.
Returns nil on failure
ReceiveBytesAsync (1)
Creates an asynchronous task to call the ReceiveBytes method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveBytesENC
Receives binary data and returns one delivery encoded as text using
encodingAlg. Chilkat first returns any data already buffered
internally. If no buffered data exists, the method performs one receive
operation; it does not loop to drain everything that may be available.
-
For plain TCP, a direct read returns at most
ReceivePacketSizebytes. -
For TLS or SSH, the returned amount is governed by the TLS record or SSH
packet rather than
ReceivePacketSize. -
Already-buffered data is returned in full, even if it exceeds
ReceivePacketSize. - A successful call can receive zero bytes during TLS renegotiation, producing an empty encoded result. Treat this as no application data yet and call the receive method again.
Common encoding names include base64, modBase64,
base32, uu, qp, url,
hex, q, b, url_oauth,
url_rfc1738, url_rfc2396, and
url_rfc3986. See
all supported
Chilkat binary encodings.
ReceiveFailReason = 10, but the
returned encoded string may contain final bytes received immediately before
the close. Process those bytes before finishing the receive loop.
Returns nil on failure
ReceiveBytesENCAsync (1)
Creates an asynchronous task to call the ReceiveBytesENC method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveBytesN
Receives exactly numBytes bytes. The method continues receiving
until the requested count is satisfied or a receive failure occurs.
Inactivity is controlled by MaxReadIdleMs.
When the requested count is successfully completed, bytes read beyond that count may remain buffered internally for the next receive operation.
Returns nil on failure
ReceiveBytesNAsync (1)
Creates an asynchronous task to call the ReceiveBytesN method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveBytesToFile
Receives one available block of bytes and appends it to the file named by
appendFilename. If Chilkat already has buffered data, that data is
used first. Otherwise, the method performs one receive operation; it does not
loop until the peer closes or until an entire file has arrived. If no data is
immediately available, it waits according to MaxReadIdleMs.
ReceivedCount even when
the overall method fails.
After a timeout or application abort, the connection is generally still open. After a peer close or reset, the connection is no longer usable for I/O.
Returns true for success, false for failure.
ReceiveBytesToFileAsync (1)
Creates an asynchronous task to call the ReceiveBytesToFile method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveCount
Reads exactly four bytes and interprets them as a signed 32-bit two's-complement integer. Byte order is controlled by BigEndian, whose default is true for network byte order.
Negative values are returned unchanged, with one exception: -1 is reserved as the failure result. If the incoming four-byte value is 0xFFFFFFFF, the method deliberately reports failure, sets LastMethodFailed, and returns -1. A legitimately transmitted value of -1 therefore cannot be received as ordinary data. There is no unsigned variant, so wire values from 0x80000000 through 0xFFFFFFFE are returned as negative signed integers.
SendCount(N) followed by ReceiveCount round-trips every signed 32-bit value except -1.ReceiveCountAsync (1)
Creates an asynchronous task to call the ReceiveCount method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveInt16
Reads exactly two bytes, interprets them as a two's-complement integer, and stores the result in ReceivedInt. Set bigEndian to true for network byte order or false for little-endian order. Set bUnsigned to true for a value from 0 through 65535; otherwise the result ranges from -32768 through 32767.
ReceivedInt remains unchanged on failure, so use the Boolean return value before reading it.Returns true for success, false for failure.
ReceiveInt16Async (1)
Creates an asynchronous task to call the ReceiveInt16 method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveInt32
Reads exactly four bytes, interprets them as a signed two's-complement integer, and stores the result in ReceivedInt. Set bigEndian to true for network byte order or false for little-endian order.
ReceivedInt remains unchanged on failure, so use the Boolean return value before reading it.Returns true for success, false for failure.
ReceiveInt32Async (1)
Creates an asynchronous task to call the ReceiveInt32 method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveNBytesENC
Receives exactly numBytes bytes and returns them encoded using
encodingAlg. Supported encoding names include
base64, modBase64, base32,
uu, qp, url, hex,
q, b, url_oauth,
url_rfc1738, url_rfc2396, and
url_rfc3986. See
all supported
Chilkat binary encodings. Inactivity is controlled by
MaxReadIdleMs.
ReceiveBytesN and ReceiveBdN, which expose partial
data on failure.
Returns nil on failure
ReceiveNBytesENCAsync (1)
Creates an asynchronous task to call the ReceiveNBytesENC method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveSb
Receives text, decodes it using StringCharset, and appends it to
sb. Chilkat first uses any plaintext already buffered internally.
Otherwise, it receives until it can append the first nonempty decoded result.
The method does not continue reading merely to drain all data that may be
available.
-
For plain TCP, the underlying direct read obtains at most
ReceivePacketSizebytes. -
For TLS or SSH, the amount is governed by the TLS record or SSH packet and
is not limited by
ReceivePacketSize. -
Already-buffered plaintext is appended in full, even if it exceeds
ReceivePacketSize. - On success, at least one received byte contributes to the appended text; this method does not return success with an empty receive result.
ReceiveFailReason = 10, but
sb may contain final text received immediately before the close.
Returns true for success, false for failure.
ReceiveSbAsync (1)
Creates an asynchronous task to call the ReceiveSb method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveString
Receives text and decodes it using StringCharset. Chilkat first
uses any plaintext already buffered internally. Otherwise, it receives until
it can return the first nonempty decoded result. The method does not continue
reading merely to drain all data that may be available.
-
For plain TCP, the underlying direct read obtains at most
ReceivePacketSizebytes. -
For TLS or SSH, the amount is governed by the TLS record or SSH packet and
is not limited by
ReceivePacketSize. -
Already-buffered plaintext is returned in full, even if it exceeds
ReceivePacketSize. - On success, the returned text represents at least one received byte; this method does not produce a successful empty result.
ReceiveFailReason = 10, but the
returned string may contain final text received immediately before the close.
For APIs that return a string directly, check LastMethodFailed
without discarding the returned value.
Returns nil on failure
ReceiveStringAsync (1)
Creates an asynchronous task to call the ReceiveString method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveStringMaxN
Receives and decodes text like ReceiveString, but returns at most maxByteCount input bytes. The limit is measured in bytes, not Unicode characters.
Returns nil on failure
ReceiveStringMaxNAsync (1)
Creates an asynchronous task to call the ReceiveStringMaxN method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveStringUntilByte
Receives bytes until the raw byte value lookForByte is found.
The delimiter is excluded from the returned string. The bytes preceding the
delimiter are then decoded using StringCharset.
The delimiter search is purely byte-oriented and does not recognize character boundaries. A match may therefore occur inside the encoded representation of a multibyte character.
0x80 with an
ASCII-compatible charset such as UTF-8, an ISO-8859 encoding, a Windows-125x
encoding, or Shift-JIS.
Returns nil on failure
ReceiveStringUntilByteAsync (1)
Creates an asynchronous task to call the ReceiveStringUntilByte method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveToCRLF
Receives text through a CRLF line terminator and returns the text including
the terminator. Chilkat encodes the CR followed by LF characters using
StringCharset, then searches the incoming byte stream for that
exact encoded sequence. The accumulated bytes are decoded using the same
charset after the delimiter is found.
0D 0A. With a wide charset such as UTF-16LE, the encoded
delimiter is different, for example 0D 00 0A 00.
Returns nil on failure
ReceiveToCRLFAsync (1)
Creates an asynchronous task to call the ReceiveToCRLF method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveUntilByte
Reads bytes until lookForByte is encountered and returns all bytes up to and including that byte. The argument must identify a one-byte value from 0 through 255.
Returns nil on failure
ReceiveUntilByteAsync (1)
Creates an asynchronous task to call the ReceiveUntilByte method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveUntilByteBd
Reads bytes until lookForByte is encountered and appends all bytes
up to and including the matching byte to bd. The delimiter must be
an integer from 0 through 255 and is matched as a raw
byte value.
false, but everything
received while searching remains appended to bd. These bytes are
included in ReceivedCount, have been consumed from the connection,
and are not retained internally for a later receive call.
A timeout or application abort generally leaves the connection open. A peer close or reset leaves it unavailable for further I/O.
Returns true for success, false for failure.
ReceiveUntilByteBdAsync (1)
Creates an asynchronous task to call the ReceiveUntilByteBd method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveUntilMatch
Receives bytes until the exact byte sequence represented by
matchStr is found. Chilkat first encodes
matchStr using StringCharset, then performs a
case-sensitive, byte-for-byte comparison against the incoming stream. No
case folding, Unicode normalization, or text-level comparison is performed.
The match may span multiple underlying network reads. After the delimiter is
found, the complete accumulated byte sequence is decoded using
StringCharset and returned as text. The returned text includes
the matching delimiter.
matchStr is empty, or if it encodes to zero bytes under the
current StringCharset, the method fails immediately with
ReceiveFailReason = 4. No data is read from the connection and
the returned string is empty.
ReceiveFailReason is 10.
On success, bytes read beyond the delimiter may remain buffered internally
for the next receive call. This is why ReceivedCount can increase
by more than the number of bytes represented by the returned string.
Returns nil on failure
ReceiveUntilMatchAsync (1)
Creates an asynchronous task to call the ReceiveUntilMatch method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ReceiveUntilMatchSb
Receives bytes until the exact byte sequence represented by
matchStr is found. Chilkat first encodes
matchStr using StringCharset, then performs a
case-sensitive, byte-for-byte comparison against the incoming stream. The
match may span multiple underlying network reads.
After the delimiter is found, the accumulated bytes are decoded using
StringCharset and appended to sb. The appended text
includes the matching delimiter.
matchStr is empty, or if it encodes to zero bytes under the
current StringCharset, the method fails immediately with
ReceiveFailReason = 4. No data is read and sb is
left unchanged.
false and
does not modify sb. Bytes consumed while searching are included
in ReceivedCount, are discarded, are not retained for a later
receive, and cannot be recovered. If an orderly peer close is detected,
ReceiveFailReason is 10.
On success, bytes read beyond the delimiter may remain buffered internally for the next receive operation.
Returns true for success, false for failure.
ReceiveUntilMatchSbAsync (1)
Creates an asynchronous task to call the ReceiveUntilMatchSb method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
ResetPerf
Restarts one direction of connection-level transfer-rate measurement. Set rcvPerf to true to reset receive measurement for RcvBytesPerSec; set it to false to reset send measurement for SendBytesPerSec.
SelectForReading
Waits for read-ready activity on this socket or, when this object is a socket set, on any contained socket.
timeoutMs = 0performs a nonblocking poll and returns immediately.- A positive value waits up to that many milliseconds.
- A negative value currently produces an effectively very long wait. Applications should normally use
0or a positive value rather than depend on this behavior.
| Return value | Meaning |
|---|---|
| Positive | The number of sockets in the read-ready result. |
| 0 | No socket was ready at the time of the poll or before the timeout. |
| -1 | An error occurred. |
A connected socket is read-ready when data is available or when a close/error condition can be detected. A listener is read-ready when an incoming connection is pending. Listener and connected sockets may coexist in one set, but the set does not identify which type a ready member is; the application must track that information and call AcceptNext or a receive method as appropriate.
n, iterate from 0 through n - 1, assign each value directly to SelectorReadIndex, and then operate on this socket-set object. Do not assign the value to SelectorIndex.
SelectForReadingAsync (1)
Creates an asynchronous task to call the SelectForReading method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SelectForWriting
Waits for this socket, or sockets in a socket set, to become writable without blocking.
timeoutMs = 0performs a nonblocking poll and returns immediately.- A positive value waits up to that many milliseconds.
- A negative value currently produces an effectively very long wait. Applications should normally use
0or a positive value rather than depend on this behavior.
| Return value | Meaning |
|---|---|
| Positive | The number of sockets in the write-ready result. |
| 0 | No socket was writable at the time of the poll or before the timeout. |
| -1 | An error occurred. |
n, iterate from 0 through n - 1, assign each value directly to SelectorWriteIndex, and then operate on this socket-set object. Do not assign the value to SelectorIndex.SelectForWritingAsync (1)
Creates an asynchronous task to call the SelectForWriting method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendBd
Sends bytes from binData, beginning at offset. If
numBytes is greater than 0, that many bytes are
selected; if it is 0, bytes are selected from offset
through the end. When both values are 0, the entire
BinData is selected. The selected range must be valid.
The method is synchronous and uses MaxSendIdleMs as the maximum
period during which no send progress may occur. No application message framing
is added.
Returns true for success, false for failure.
SendBdAsync (1)
Creates an asynchronous task to call the SendBd method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendByte
Sends one byte whose value is specified by value. The value must be in the range 0 through 255. The method returns after the byte has been accepted for transmission or a send failure occurs.
Returns true for success, false for failure.
SendByteAsync (1)
Creates an asynchronous task to call the SendByte method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendBytes
Sends the bytes in data over the connected TCP or TLS socket. The
method is synchronous and uses MaxSendIdleMs as the maximum period
during which no send progress may occur.
false does not mean that no bytes were sent. Part
of data may already have reached the peer. Chilkat does not retain
or queue the unsent remainder and does not report how many bytes were sent.
Although a timeout or application abort may leave the TCP connection open, the
application-protocol stream may contain a truncated message. For a
length-prefixed, delimited, or otherwise framed protocol, the safest response
is normally to close the connection and reconnect before sending another
message. A peer close or reset leaves the connection unusable for further I/O.
Returns true for success, false for failure.
SendBytesAsync (1)
Creates an asynchronous task to call the SendBytes method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendBytesENC
Decodes encodedBytes using encodingAlg, then sends the resulting binary bytes. Supported Chilkat encoding names include base64, modBase64, base32, base58, uu, qp, url, hex, q, b, url_oauth, url_rfc1738, url_rfc2396, and url_rfc3986. See all supported Chilkat binary encodings.
For example, encodedBytes="00010203040506" with encodingAlg="hex" sends seven bytes with values 00 through 06.
SendFailReason and LastErrorText.SendBytesENCAsync (1)
Creates an asynchronous task to call the SendBytesENC method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendCount
Sends byteCount as its four-byte signed two's-complement bit pattern. Byte order is controlled by BigEndian, whose default is true for network byte order. Any signed 32-bit value is serialized without validation.
The peer can read the value using ReceiveCount, except that -1 is not usable as an ordinary count because ReceiveCount reserves -1 as its failure result.
Returns true for success, false for failure.
SendCountAsync (1)
Creates an asynchronous task to call the SendCount method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendInt16
Sends the low 16 bits of value as a two-byte two's-complement bit pattern. Set bigEndian to true for network byte order or false for little-endian order.
No range validation is performed. Signed values from -32768 through 32767 and unsigned values from 0 through 65535 can be represented directly. Any other integer is silently truncated to its low 16 bits, equivalent to taking the value modulo 65536.
40000 writes 0x9C40, -1 writes 0xFFFF, 65536 writes 0x0000, and 70000 writes 0x1170.Returns true for success, false for failure.
SendInt16Async (1)
Creates an asynchronous task to call the SendInt16 method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendInt32
Sends value as its complete four-byte signed two's-complement bit pattern. Set bigEndian to true for network byte order or false for little-endian order.
The parameter is a signed 32-bit integer and there is no unsigned overload, but every 32-bit wire pattern can be represented by passing the signed integer having that bit pattern. For example, passing -1 writes 0xFFFFFFFF. Because the input is already 32 bits, no bits are truncated.
Returns true for success, false for failure.
SendInt32Async (1)
Creates an asynchronous task to call the SendInt32 method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendSb
Encodes the contents of sb using StringCharset and sends the resulting bytes. The method is synchronous and uses MaxSendIdleMs as the send-progress inactivity limit.
StringBuilder content.Returns true for success, false for failure.
SendSbAsync (1)
Creates an asynchronous task to call the SendSb method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendString
Encodes stringToSend using StringCharset and sends the
resulting bytes over the connected TCP or TLS socket. The method is
synchronous and uses MaxSendIdleMs as the maximum period during
which no send progress may occur. No delimiter, terminator, or length prefix
is added automatically.
Returns true for success, false for failure.
SendStringAsync (1)
Creates an asynchronous task to call the SendString method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SendWakeOnLan
Sends a Wake-on-LAN magic packet for macAddress to the UDP broadcast address ipBroadcastAddr and port. The MAC address is six bytes written as hexadecimal, for example 000102030405. Ports 7 and 9 are commonly used.
Call this method without first calling Connect. The target computer must have Wake-on-LAN enabled in firmware, the network adapter, and the operating system, and the network must permit the broadcast packet.
Returns true for success, false for failure.
SendWakeOnLan2
Sends the same Wake-on-LAN magic packet as SendWakeOnLan and appends a SecureOn password. password is a hexadecimal string representing four or six bytes.
Returns true for success, false for failure.
SetSslClientCert
Configures cert as the client certificate for subsequent TLS connections. The certificate must have access to its private key. Use this only when the server requests or requires client-certificate authentication.
Connect or ConvertToSsl. A certificate without its private key cannot prove client identity.Returns true for success, false for failure.
SetSslClientCertPem
Loads and configures a TLS client certificate and private key from PEM data or a PEM filename supplied in pemDataOrFilename. Use pemPassword when the private key is encrypted.
Returns true for success, false for failure.
SetSslClientCertPfx
Loads and configures a TLS client certificate and private key from the PFX/P12 file pfxFilename, using pfxPassword. Use this only when the server requests or requires client-certificate authentication.
Returns true for success, false for failure.
SleepMs
Pauses the calling thread for approximately millisec milliseconds. This is a convenience method and does not perform network I/O or keep a connection alive.
SshAuthenticatePk
Authenticates the SSH tunnel session as sshLogin using privateKey. Call SshOpenTunnel first. The SSH server must have the corresponding public key authorized for that account.
Returns true for success, false for failure.
SshAuthenticatePkAsync (1)
Creates an asynchronous task to call the SshAuthenticatePk method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SshAuthenticatePw
Authenticates the SSH tunnel session using sshLogin and sshPassword. Call SshOpenTunnel first and authenticate before opening forwarded channels.
Returns true for success, false for failure.
SshAuthenticatePwAsync (1)
Creates an asynchronous task to call the SshAuthenticatePw method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SshCloseTunnel
Closes the SSH tunnel opened by SshOpenTunnel and terminates its forwarded channels. It does not close unrelated SSH objects or connections.
Returns true for success, false for failure.
SshCloseTunnelAsync (1)
Creates an asynchronous task to call the SshCloseTunnel method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SshNewChannel
Opens a new port-forwarded channel through the authenticated SSH tunnel to
hostname:port and populates channel with
the connected socket. If ssl is true, Chilkat establishes TLS
to the destination inside the SSH tunnel.
maxWaitMs = 0waits indefinitely for the channel/destination connection to open.- A positive value is used as supplied; unlike
Connect, values below100milliseconds are not raised to a 100-millisecond minimum. - Negative values have no defined meaning and should not be used.
Multiple channels can share one authenticated SSH tunnel and can target different destination host/port pairs.
SshOpenTunnel and authenticate successfully before opening
channels.
Returns true for success, false for failure.
SshNewChannelAsync (1)
Creates an asynchronous task to call the SshNewChannel method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
SshOpenTunnel
Connects to the SSH server at sshHostname:sshPort and
initializes an SSH tunneling session. Port 22 is conventional but
not required.
After this succeeds, authenticate with SshAuthenticatePw or
SshAuthenticatePk, then open forwarded destination channels with
SshNewChannel. Multiple channels can share the same authenticated
tunnel.
MaxReadIdleMs and
MaxSendIdleMs. The default value of 0 for those
properties permits an indefinite wait while no progress is made.
Returns true for success, false for failure.
SshOpenTunnelAsync (1)
Creates an asynchronous task to call the SshOpenTunnel method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
StartTiming
Starts or restarts the object's convenience timer. Read ElapsedSeconds to obtain the whole number of seconds since this call.
TakeConnection
Moves the active connection from cSocket into this object. This object first releases its reference to any connection it previously held. Unlike TakeSocket, this method does not add a member to a socket set.
After success, cSocket holds no connection. It may be closed, destroyed, or reused immediately without affecting the transferred connection. Ownership is exclusive after the move; only this destination object controls the transferred connection.
DupSocket only when two wrappers must refer to the same underlying connection.Returns true for success, false for failure.
TakeSocket
Moves the connection out of sock and into a newly created member of this object's socket set. After one or more successful calls, this object acts as a set of connected and/or listener sockets.
After success, sock holds no connection. It may be closed, destroyed, or reused immediately without affecting the transferred connection. The new set member owns the connection independently; there is no shared ownership to coordinate.
SelectorIndex to select a direct member. After SelectForReading or SelectForWriting, assign the ready position directly to SelectorReadIndex or SelectorWriteIndex.TakeSocket adds a new member to the socket set. TakeConnection moves a connection into the receiving object itself and is not a set-building method.Returns true for success, false for failure.
TlsRenegotiate
Requests TLS renegotiation on an established TLS connection, causing another handshake to negotiate new security parameters where the protocol and peer support it.
Returns true for success, false for failure.
topTlsRenegotiateAsync (1)
Creates an asynchronous task to call the TlsRenegotiate method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
UseSsh
Configures this socket to route subsequent Connect calls through the already connected and authenticated Ssh object. The destination host and port passed to Connect are reached by SSH port forwarding rather than by a direct TCP connection.
This is one of several SSH-tunneling models in Chilkat. Alternatives include this class's SshOpenTunnel/SshNewChannel workflow and the separate SshTunnel class for background static or dynamic forwarding.
Ssh object must remain connected and authenticated while the forwarded socket connection is being established and used.Returns true for success, false for failure.
Events
To implement an event callback, your application would define and implement a class that inherits from CkoBaseProgress. Your application can implement methods to override some or all of the default/empty method implementations of the CkoBaseProgress base class.
For example:
class MySocketProgress : CkoBaseProgress {
override func ProgressInfo(name: String!, value: String!) {
// application code goes here...
print(name + ": " + value)
}
override func AbortCheck(abort: UnsafeMutablePointer) {
// application code goes here...
// To abort the operation, set this equal to true instead of false.
abort.memory = false
}
override func PercentDone(pctDone: NSNumber!, abort: UnsafeMutablePointer) {
// application code goes here...
print(pctDone)
// To abort the operation, set this equal to true instead of false.
abort.memory = false
}
// For asynchronous method calls.
override func TaskCompleted(task: CkoTask!) {
// application code goes here...
}
}
func someAppFunction() {
// Demonstrate how to set the event callback object...
let socket = CkoSocket()
let mySocketProgress = MySocketProgress()
socket.setEventCallbackObject(mySocketProgress)
// ...
// ...
// ...
}
AbortCheck
Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.
PercentDone
This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).
The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.
To abort the operation, set the abort output argument to true. This will cause the method to terminate and return a failure status or corresponding failure value.
ProgressInfo
This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.
Note: Some Chilkat methods don't fire any ProgressInfo events.
TaskCompleted
Called from the background thread when an asynchronous task completes.
Deprecated
ListenIpv6
This property and PreferIpv6 are two names for the same underlying setting. Reading or writing either property reads or changes the same value.
For a listener, when ClientIpAddress is empty, the default false value causes BindAndListen and BindAndListenPortRange to bind to 0.0.0.0. Set it to true to bind to ::. When ClientIpAddress contains an explicit address, that address determines both the bind address and its IPv4 or IPv6 family.
PreferIpv6, changing ListenIpv6 also changes the address-family preference used when an outbound hostname resolves to both IPv4 and IPv6 addresses.AcceptNextConnection
AcceptNext instead.
Waits for and accepts the next incoming connection on a listening socket. On
success, a new Socket object is returned.
maxWaitMs = 0waits indefinitely for an incoming connection.- A positive value waits up to that many milliseconds.
- Negative values have no defined meaning and should not be used.
maxWaitMs; handshake inactivity uses
MaxReadIdleMs and MaxSendIdleMs. Leaving the idle
timeouts at 0 permits an unresponsive client to keep the
handshake waiting indefinitely.
Returns nil on failure
AcceptNextConnectionAsync (1) (2)
Creates an asynchronous task to call the AcceptNextConnection method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure
CloneSocket
DupSocket instead.Returns another Socket object that shares the same underlying TCP or TLS connection. Reads and writes made through either object operate on the same byte stream.
Returns nil on failure
GetMyCert
GetMyServerCert instead.Returns the certificate configured for this object when it is acting as a TLS server. The certificate is initially supplied to InitSslServer.
Returns nil on failure
GetReceivedClientCert
GetRcvdClientCert instead.Returns the client certificate at the zero-based index received during the TLS handshake on an accepted server-side connection. Use NumReceivedClientCerts to determine the valid range.
AcceptNextConnection, not on the listener. The server application remains responsible for deciding whether the certificate authorizes the client.Returns nil on failure
GetSslServerCert
GetServerCert instead.Returns the certificate presented by the remote TLS server for the current client-side TLS connection. It returns a null reference when the socket is not connected or the connection is not using TLS.
Returns nil on failure
LastJsonData
GetLastJsonData instead.Returns a JSON object containing additional details produced by the most recently called method when such details are available.
Returns nil on failure
SshOpenChannel
SshNewChannel instead.Opens a port-forwarded channel through the authenticated SSH tunnel to hostname:port. If ssl is true, Chilkat performs TLS to the destination inside the SSH tunnel. maxWaitMs limits destination connection establishment.
Returns nil on failure
SshOpenChannelAsync (1) (2)
Creates an asynchronous task to call the SshOpenChannel method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Returns nil on failure