WinSocket

Summary

Represents a Windows TCP socket handle returned by SocketManager. The socket is automatically closed when garbage collected.

Methods

MethodReturns
Accept()WinSocket
Recv(length: number)string
Send(data: string)number
PollConnectionStatus()integer
IsOutgoingConnectionUsable()boolean
Close()void
Shutdown()void
ShutdownSend()void

Methods

Accept

Accepts an incoming client connection on a listening socket. Returns nil if no client is ready (non-blocking, WSAEWOULDBLOCK). Raises an error if the accept call fails for any other reason.

Returns

TypeDescription
WinSocketclientSocket The accepted client socket, or nil if no connection is pending.

Recv

WinSocket:Recv(length: number): string

Receives data from the socket up to length bytes. Returns an empty string if the connection was closed gracefully. Raises an error if the recv call fails.

Parameters

NameTypeDescription
lengthnumberThe maximum number of bytes to receive.

Returns

TypeDescription
stringdata The received data.

Send

WinSocket:Send(data: string): number

Sends a string of data over the socket. Raises an error if the send call fails.

Parameters

NameTypeDescription
datastringThe data to send.

Returns

TypeDescription
numberbytesSent The number of bytes successfully sent.

PollConnectionStatus

WinSocket:PollConnectionStatus(): integer

Specifically for outgoing request sockets. Returns 0 if pending, 1 if successfully connected (and therefore can properly send data), and 2 if failed.

Returns

TypeDescription
integer

IsOutgoingConnectionUsable

WinSocket:IsOutgoingConnectionUsable(): boolean

Specifically for outgoing request sockets. Returns true if specifically after PollConnectionStatus() returned 1 and therefore had no connection errors.

Returns

TypeDescription
boolean

Close

WinSocket:Close(): void

Closes the socket connection and releases the handle.

Shutdown

WinSocket:Shutdown(): void

Disables sends or receives on a socket. Recv() is one of the functionalities that will be disabled if this is used.

ShutdownSend

WinSocket:ShutdownSend(): void

Disables sends on a socket. Recv() will not be disabled and will send any lingering data.