Documentation

Net::Socket

Class

A non-blocking TCP socket.

Methods

bool Connect(const string&in host, uint16 port)

Start a connection to the given host and port. This is non-blocking and will immediately return. Use IsReady() to wait for the connection to be ready.

Returns bool
bool Listen(const string&in host, uint16 port)

Starts listening on the given host and port.

Returns bool
bool Listen(uint16 port)

Starts listening on the given port using 0.0.0.0 as the host. Note that this will open up the port to the LAN, which may not be what you want.

Returns bool
void Close()

Closes the socket.

Net::Socket@ Accept()

When this socket is listening, attempts to accept a client connection if one is trying to connect. If there is, it will be returned. If no client is waiting, this will return null.

Returns Net::Socket@
string GetRemoteIP()

Get the host IP address associated with this socket.

Returns string
Deprecated
bool CanRead()

This method is deprecated and should not be used. Consider using IsReady(), IsHungUp(), or Available() instead, depending on your use-case.

Returns bool
Deprecated
bool CanWrite()

This method is deprecated and should not be used. Use IsReady() instead.

Returns bool
bool IsReady()

Returns true if the socket is ready to be used.

Returns bool
bool IsHungUp()

Returns true if the socket state currently has the hangup flag. Note that this flag may be set while there is still data in the buffer that can be read.

Returns bool
int Available()

Returns the number of bytes available to be read from the socket buffer.

Returns int
string ReadRaw(int bytes)

Reads the given number of bytes and return it as a string.

Returns string
MemoryBuffer@ ReadBuffer(int bytes)

Reads the given number of bytes and return it as a MemoryBuffer.

Returns MemoryBuffer@
bool WriteRaw(const string&in str)

Writes the given string to the socket as-is. Returns false if the write did not succeed. Note that this behavior differs from Write(const string &in).

Returns bool
bool ReadLine(string&out str)

Attempts to read up until the next newline character, and outputs the string (including the newline character) in str. If no newline character is encountered, it will return false, leave str unmodified, and no bytes will be consumed from the buffer.

Returns bool
bool WriteLine(const string&in)

Writes a line of text to the socket. Returns false if the write did not succeed. This behaves the same as WriteRaw(), except a newline is appended.

Returns bool
int8 ReadInt8()

Reads an 8 bit signed integer from the buffer.

Returns int8
int16 ReadInt16()

Reads a 16 bit signed integer from the buffer.

Returns int16
int ReadInt32()

Reads a 32 bit signed integer from the buffer.

Returns int
int64 ReadInt64()

Reads a 64 bit signed integer from the buffer.

Returns int64
uint8 ReadUint8()

Reads an 8 bit unsigned integer from the buffer.

Returns uint8
uint16 ReadUint16()

Reads a 16 bit unsigned integer from the buffer.

Returns uint16
uint ReadUint32()

Reads a 32 bit unsigned integer from the buffer.

Returns uint
uint64 ReadUint64()

Reads a 64 bit unsigned integer from the buffer.

Returns uint64
float ReadFloat()

Reads a 32 bit float from the buffer.

Returns float
double ReadDouble()

Reads a 64 bit float from the buffer.

Returns double
string ReadString()

Reads a string length from the buffer as a 32 bit unsigned integer, followed by the actual string. This complements Write(const string &in).

Returns string
bool Write(int8)

Writes an 8 bit signed integer to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(int16)

Writes a 16 bit signed integer to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(int)

Writes a 32 bit signed integer to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(int64)

Writes a 64 bit signed integer to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(uint8)

Writes an 8 bit unsigned integer to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(uint16)

Writes a 16 bit unsigned integer to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(uint)

Writes a 32 bit unsigned integer to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(uint64)

Writes a 64 bit unsigned integer to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(float)

Writes a 32 bit float to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(double)

Writes a 64 bit double to the socket. Returns false if the write did not succeed.

Returns bool
bool Write(const string&in)

Writes a 32 bit unsigned integer for the length of the string to the socket, followed by the actual string. Returns false if the write did not succeed. Note that this behavior differs from WriteRaw().

Returns bool
bool Write(MemoryBuffer&in, uint64 size = 0)

Reads a number of bytes from the given MemoryBuffer and writes them to the socket.

Returns bool