[edit] vx.Socket
An object that represents a verge socket handle and performs various network operations.
[edit] Constructors
vx.Socket()
- This creates a Socket object. It does not automatically perform any operations. If you construct a Socket without parameters, you must either
Connect() or GetConnection() successfully before can do anything else with it. This is mostly intended for use with GetConnection() to make a server with Verge.
vx.Socket(address, [port])
- Wraps around a raw socket handle. On construction, creates and connects to a new socket at the specified address on the supplied port. If no port is specified, it assumes Verge's default port (45150).
[edit] Methods
vx.Socket:Free()
vx.Socket:Close()
- Destroys the socket handle. Any further socket operation on this object will probably not end so pretty.
vx.Socket:Connect(address, port)
- Connects the socket to the supplied address and port. It is very unlikely you will ever nead this as it is performed for you on Socket construction.
vx.Socket:Listen([port])
vx.Socket:GetConnection([port])
- Checks for new connections on the specified port. If no port is supplied, it will use Verge's default (45150). If a new connection is found, the Socket will then assume that connection; if you are accepting multiple connections, you will need to create a new Socket for every connection.
vx.Socket:Connected() -> boolean
- Returns whether or the socket is currently connected. Much like its VergeC equivalent, it shouldn't be considered particularly reliable and implementing an alternative method, such as a timeout, is recommended.
vx.Socket:HasData() -> boolean
- Returns whether or not there is any data in the socket's queue waiting to be read/processed.
vx.Socket:ByteCount() -> number
- Returns the number of bytes/characters currently in the socket's queue waiting to be read/processed. This is primarily intended for use with getting and sending raw data. It should be noted, though, that if a verge int or string packet is in the queue, the header will be included in the byte count. However, if you are using a non-raw transmissions,
HasData() should be sufficient (and probably faster) than ByteCount() anyway.
vx.Socket:GetInt() -> number
- Returns an integer number value acquired from the socket's data queue. If it receives a non-integer value, bad things will happen. Make certain that a socket only attempts to retrieve data of a type that is actualy being sent to it.
vx.Socket:SendInt(value)
- Sends an integer number value through the socket. If the other end is not expecting an integer, something bad may happen to it, but the sender will probably be unharmed.
vx.Socket:GetString() -> string
- Returns a string value acquired from the socket's data queue. If it receives a non-string value, bad things will happen. Make certain that a socket only attempts to retrieve data of a type that is actually being sent to it.
vx.Socket:SendString(message)
- Sends a string value through the socket. If the other end is not expecting a string, something bad may happen to it, but the sender will probably be unharmed.
vx.Socket:GetRaw(length) -> string
- Returns a string value acquired from the socket's data queue. This string does not contain any of the Verge-string header information and is best suited for communicating with a non-Verge program within Verge itself. Exercise extreme caution when using this as there is even less hand-holding than with the other socket operations.
vx.Socket:SendRaw(message)
- Sends a raw (non-Verge) string through the socket. This string does not contain any of the Verge-string header information and is best suited for communicating with a non-Verge program within Verge itself. Exercise extreme caution when using this as there is even less hand-holding than with the other socket operations.