NetworkSocket
Methods
send
Sends data over the socket, and returns the number of bytes sent.
:send(data: string | buffer, offset: number?): numberParameters
data: string | buffer- The data to send.offset: number?- The offset to start sending from.- default:
0
- default:
Throws
- Network Error
- Memory Error
sendMsg
Sends data over the socket, and returns the number of bytes sent.
:sendMsg(port: number, address: string, data: string | buffer, offset: number?): numberParameters
port: number- The port to send the message to.address: string- The address to send the message to.data: string | buffer- The data to send.offset: number?- The offset to start sending from.- default:
0
- default:
Throws
- Network Error
- Memory Error
recv
:recv(max_size: number?): bufferParameters
max_size: number?- The maximum size of the data to receive.- default:
8192
- default:
Throws
- Network Error
- Memory Error
recvMsg
:recvMsg(max_size: number?): (export type NetworkAddress = {
family: number,
port: number,
address: string,
}NetworkAddressexport type NetworkAddress = {
family: number,
port: number,
address: string,
}, buffer)Parameters
max_size: number?- The maximum size of the message to receive.- default:
8192
- default:
Throws
- Network Error
- Memory Error
accept
Yields and waits for a connection to be made on the socket, and returns a NetworkSocket object.
:accept(): NetworkSocketThrows
- IO Error
connect
Connects the socket to the specified address and port.
:connect(address: string, port: number): ()Parameters
address: string- The address to connect to.port: number- The port to connect to.
Throws
- Network Error
listen
Starts listening for incoming connections on the socket.
:listen(backlog: number?): ()Parameters
backlog: number?- The maximum number of connections to backlog.- default:
128
- default:
Throws
- IO Error
bindIp
Binds the socket to the specified address and port.
:bindIp(address: string, port: number): ()Parameters
address: string- The address to bind to.port: number- The port to bind to.
Throws
- Network Error
getName
:getName(): export type NetworkAddress = {
family: number,
port: number,
address: string,
}NetworkAddressexport type NetworkAddress = {
family: number,
port: number,
address: string,
}Throws
- Network Error
- Memory Error
setOption
Sets a socket option on the socket.
:setOption(level: number, optname: number, value: boolean | string | buffer): ()Parameters
level: number- The level of the option.optname: number- The name of the option.value: boolean | string | buffer- The value of the option.
Throws
- Network Error
close
Closes the socket.
:close(): ()Throws
- IO Error
- Network Error
isOpen
Returns if the socket is open.
:isOpen(): booleanLast updated on