Addon Entry

Now supporting the newest garrysmods.org

New : UserScript to add a search button to any garrysmod.org download page Script Page Install It!

Mirrors

There are no mirrors, request one in the comment section below.
File: GSocket Module
Version: 0
Garrysmod.org URL: http://www.garrysmod.org/downloads/?a=view&id=70497
Description: Lua Module that interfaces with LuaSocket providing a much easier object orientated system than what LuaSocket gives you.

You need the LuaSocket binary for this to work!

LuaSocket Binary: http://www.facepunch.com/showthread.php?t=495940

Usage:

There are several hooks you can use in order to use the system. You must use hook.Add to hook them, not GM: functions.

ConnectionClosed( handle, by )
handle = Client Object
by = String

MessageRecieved( handle, msg )
handle = Client Object
msg = String

ServerHalted( handle )
handle = Server Object

ShouldAcceptConnection( handle, ip, port )
handle = Server Object
ip = Client IP Address
port = Port Number
( RETURNS: boolean )

OnConnection( server, handle )
server = Server Object
handle = New Client Object
( Note: This is called upon incoming connection )

ServerStarted( handle )
handle = Server Object

ConnectionMade( handle )
handle = Client Object
( Note: This is called upon successful outgoing connection )

Stuff you can do with the handle objects:

client:Send( message ) - Sends a message
client:GetPort() - Gets the remote port
client:GetIP() - Gets the remote IP address
client:IsValid() - Gets if the connection is still open and valid
client:Close() - Closes the connection

server:IsValid() - Gets if the server is still listening
server:Stop() - Stops the server

Stuff you can do with the gsocket module:

gsocket.Listen( ip, port, maxconnections )
ip = IP address of the server (must be the IP address the server uses to listen on)
port = Port number to use
maxconnections = Maximum simultaneous connections
( RETURNS: Server Object )

gsocket.Connect( ip, port )
ip = IP address of the remote server to connect to
port = Port of the remote server to connect to
( RETURNS: Client Object )

Other notes:

Always check that the connections are still open by using object:IsValid()!

Image: GSocket