Module socket.wrapper
Pure LuaJIT bindings for Windows and Linux native socket libraries.
Module that provides platform-independant wrappers for socket-related functions while keeping the platform-dependant behaviour and error identical.
See also:
Info:
- Copyright: 2026
- Release: 0.0.0
- License: CC0 1.0 Universal (CC0 1.0) (Public Domain)
- Author: Herwin Bozet (NibblePoker)
Functions
| init () | Initializes the native socket libraries if required. |
| deinit () | De-initializes the native socket libraries if required, and closes all active sockets. |
| socket (af, socktype, protocol) | Creates a new socket of a given address family, type, and protocol. |
| closesocket (s) | Closes a given socket that was previously created. |
| connect (s, af, port, host) | Creates a connection to a distant host via a given socket. |
| bind (s, af, port, host) | Binds a given socket to some interface, or none. |
| shutdown (s, how) | Closes a connection to distant host made via a given socket. |
| send (s, data, len, flags) | Sends data over a given socket |
| ioctlsocket (s, cmd, arg) | Sends some IOCTL command and return any potential result. |
Fields
| bindings | Link to the socket.bindings module. |
| constants | Link to the socket.constants module. |
| winsock_version | Defines which Winsock version is used when calling WSAStartup via init. |
Functions
- init ()
-
Initializes the native socket libraries if required.
???
Returns:
-
boolean
trueif the operation succeeded,falseotherwise. -
integer Error code if the operation was a failure,
0otherwise.
See also:
-
boolean
- deinit ()
-
De-initializes the native socket libraries if required, and closes all active sockets.
???
Returns:
-
boolean -
trueif the operation succeeded,falseotherwise. -
integer Error code if the operation was a failure,
0otherwise.
See also:
-
boolean -
- socket (af, socktype, protocol)
-
Creates a new socket of a given address family, type, and protocol.
Requires a prior call to
init()on some platforms.Parameters:
- af
integer An address family from the
bindings.AF_*constants, or theAddressFamiliesenum. - socktype
integer A socket type from the
bindings.SOCK_*constants, or theSocketTypesenum. - protocol
integer An address family from the
bindings.IPPROTO_*/bindings.BTHPROTO_*constants, or theProtocolsenum.
Returns:
-
SOCKET? A non-nil value representating the socket if opened,
nilotherwise. -
integer Error code if the operation was a failure,
0otherwise.
See also:
- af
integer An address family from the
- closesocket (s)
-
Closes a given socket that was previously created.
Parameters:
- s SOCKET The socket to close.
Returns:
-
boolean
trueif the operation succeeded,falseotherwise. -
integer Error code if the operation was a failure,
0otherwise.
See also:
- connect (s, af, port, host)
-
Creates a connection to a distant host via a given socket.
Parameters:
- s SOCKET The socket over which the connection will pass.
- af
integer An address family from the
bindings.AF_*constants, or theAddressFamiliesenum. - port integer The remote host's port.
- host string The remote host's hostname/IP/address/...
Returns:
-
boolean
trueif the operation succeeded,falseotherwise. -
integer Error code if the operation was a failure,
0otherwise.
See also:
- bind (s, af, port, host)
-
Binds a given socket to some interface, or none.
Parameters:
- s SOCKET The socket that should be bound.
- af
integer An address family from the
bindings.AF_*constants, or theAddressFamiliesenum. - port integer The bound port.
- host
string The bound interface's address, or a constant from the
bindings.INADDR_*family, or theBindingAddressesenum.
Returns:
-
boolean
trueif the operation succeeded,falseotherwise. -
integer Error code if the operation was a failure,
0otherwise.
See also:
- shutdown (s, how)
-
Closes a connection to distant host made via a given socket.
Parameters:
- s SOCKET The socket whose connection should be terminated.
- how
integer A combination of shutdown flags from the
bindings.SD_*constants, or theShutdownFlagsenum.
Returns:
-
boolean
trueif the operation succeeded,falseotherwise. -
integer Error code if the operation was a failure,
0otherwise.
See also:
- send (s, data, len, flags)
-
Sends data over a given socket
Parameters:
- s SOCKET The socket over which data is to be sent.
- data any The data to send, its length will be calculated automatically.
- len integer? Leave empty to auto-calculate the data length. (Remove in the future, only OOP version shoud do this !)
- flags integer? Optional flags used to influence the way data is sent.
Returns:
-
integer bytes_sent The amount of bytes sent, or
SOCKET_ERRORif an error occured. - ioctlsocket (s, cmd, arg)
-
Sends some IOCTL command and return any potential result.
This function doesn't check if the command is valid !
Parameters:
- s SOCKET The socket over which data is to be sent.
- cmd integer ???
- arg integer ???
Returns:
-
boolean
trueif the operation succeeded,falseotherwise.Or
-
u_long The value that may have been returned by the ioctlsocket call, or the original one from the
argparameters. - integer Error code if the operation was a failure.
Fields
- bindings
-
Link to the socket.bindings module.
See also:
- constants
-
Link to the socket.constants module.
See also:
- winsock_version
-
Defines which Winsock version is used when calling
WSAStartupvia init.
The format forMAJOR.MINORis(MAJOR & 0x00FF) | ((MINOR << 8) | 0xFF00).
Has no effect on non-Windows platforms.