Provides TCP client and server socket operations, WebSocket client connections, synchronous message reads, optional asynchronous connection setup, event callbacks, lifecycle control, timeout and keep-alive configuration, and endpoint inspection.
Object functions
- available [1.14.11+]
Returns whether a line can be read without blocking.
- close [1.14.11+]
Closes the connected client and server sockets and releases their streams. Returns
truewhen they close successfully. - connect [1.10.11+]
Connects to a TCP server at the specified hostname and port, or to a WebSocket using a
ws://orwss://address. The optional asynchronous flag defaults tofalse. Set it totruefor non-blocking WebSocket setup. Returnstrueif the connection is established or the asynchronous connection attempt has started, otherwisefalse. - flush [1.14.11+]
Flushes pending output to the connected socket. Returns
true. - is_connected [1.14.11+]
Returns whether the socket currently has an open client connection.
- local_address [1.14.11+]
Returns the local IP address used by the socket.
- local_port [1.14.11+]
Returns the local port used by the socket.
- on_close [1.14.11+]
Registers a callback for WebSocket close events.
- on_error [1.14.11+]
Registers a callback for WebSocket errors.
- on_message [1.14.11+]
Registers a callback for each received WebSocket text message.
- on_open [1.14.11+]
Registers a callback for the WebSocket open event.
- open [1.10.11+]
Opens a TCP server socket on the given port and blocks while waiting for a client to connect. Once connected, it reads incoming data line-by-line and executes the provided function for each received line. Returns
trueif the server ran successfully, otherwisefalse. - read [1.14.11+]
Reads the next line from the connected socket. Returns
undefinedwhen the remote endpoint closes the stream. - remote_address [1.14.11+]
Returns the remote IP address used by the socket.
- remote_port [1.14.11+]
Returns the remote port used by the socket.
- set_keep_alive [1.14.11+]
Enables or disables TCP keep-alive for the connection. Returns
true. - set_timeout [1.14.11+]
Sets the read timeout in milliseconds. A value of zero waits indefinitely. Returns
true. - write [1.10.11+]
Writes a line of text to the connected socket and flushes the output stream. A newline character is appended automatically. Returns
true.

There are no comments on this page.
Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days. Your email address is stored so that replies can be sent to your email address.
Comments powered by BalfComment