WinSocket
Summary
Represents a Windows TCP socket handle returned by SocketManager. The socket is automatically closed when garbage collected.
Methods
| Method | Returns |
|---|---|
| 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
| Type | Description |
|---|---|
| WinSocket | clientSocket The accepted client socket, or nil if no connection is pending. |
Recv
WinSocket:Recv(length: number): stringReceives 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
| Name | Type | Description |
|---|---|---|
| length | number | The maximum number of bytes to receive. |
Returns
| Type | Description |
|---|---|
| string | data The received data. |
Send
WinSocket:Send(data: string): numberSends a string of data over the socket. Raises an error if the send call fails.
Parameters
| Name | Type | Description |
|---|---|---|
| data | string | The data to send. |
Returns
| Type | Description |
|---|---|
| number | bytesSent The number of bytes successfully sent. |
PollConnectionStatus
WinSocket:PollConnectionStatus(): integerSpecifically for outgoing request sockets. Returns 0 if pending, 1 if successfully connected (and therefore can properly send data), and 2 if failed.
Returns
| Type | Description |
|---|---|
| integer |
IsOutgoingConnectionUsable
WinSocket:IsOutgoingConnectionUsable(): booleanSpecifically for outgoing request sockets. Returns true if specifically after PollConnectionStatus() returned 1 and therefore had no connection errors.
Returns
| Type | Description |
|---|---|
| boolean |
Close
WinSocket:Close(): voidCloses the socket connection and releases the handle.
Shutdown
WinSocket:Shutdown(): voidDisables sends or receives on a socket. Recv() is one of the functionalities that will be disabled if this is used.
ShutdownSend
WinSocket:ShutdownSend(): voidDisables sends on a socket. Recv() will not be disabled and will send any lingering data.