A non-blocking TCP socket.
A non-blocking TCP socket.
Net::Socket@ Socket()
Net::Socket@ 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.
bool bool Listen(const string&in host, uint16 port)
Starts listening on the given host and port.
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.
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.
Net::Socket@ bool CanRead()
This method is deprecated and should not be used. Consider using IsReady(), IsHungUp(), or Available() instead, depending on your use-case.
bool bool CanWrite()
This method is deprecated and should not be used. Use IsReady() instead.
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.
bool int Available()
Returns the number of bytes available to be read from the socket buffer.
int MemoryBuffer@ ReadBuffer(int bytes)
Reads the given number of bytes and return it as a MemoryBuffer.
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).
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.
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.
bool 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).
string bool Write(int8)
Writes an 8 bit signed integer to the socket. Returns false if the write did not succeed.
bool bool Write(int16)
Writes a 16 bit signed integer to the socket. Returns false if the write did not succeed.
bool bool Write(int)
Writes a 32 bit signed integer to the socket. Returns false if the write did not succeed.
bool bool Write(int64)
Writes a 64 bit signed integer to the socket. Returns false if the write did not succeed.
bool bool Write(uint8)
Writes an 8 bit unsigned integer to the socket. Returns false if the write did not succeed.
bool bool Write(uint16)
Writes a 16 bit unsigned integer to the socket. Returns false if the write did not succeed.
bool bool Write(uint)
Writes a 32 bit unsigned integer to the socket. Returns false if the write did not succeed.
bool bool Write(uint64)
Writes a 64 bit unsigned integer to the socket. Returns false if the write did not succeed.
bool bool Write(float)
Writes a 32 bit float to the socket. Returns false if the write did not succeed.
bool bool Write(double)
Writes a 64 bit double to the socket. Returns false if the write did not succeed.
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().
bool bool Write(MemoryBuffer&in, uint64 size = 0)
Reads a number of bytes from the given MemoryBuffer and writes them to the socket.
bool