GithubHelp home page GithubHelp logo

gmsocks's Introduction

GMSocks

Finally a working and well written socket extension for Garrys Mod 13!

IMPORTANT! This socket library is non blocking on purpose!

Download

Grab the binaries from here: https://github.com/azarus/GMSocks/releases/download/0.1/Release.zip

Docs

There is only 2 functions for udp and it should be enough for basic networking.

string UDPReceive(number port, string ip, number bytes = 2048)

  • Retrieves data from a desired address
  • Returns nil on failure or the retrieved data.

number UDPSend(number port, string ip, string data, number length)

  • Sends data to the desired address
  • Returns the number of bytes sent

FOR A COMPLETE EXAMPLE LOOK AT Example.lua: https://github.com/azarus/GMSocks/blob/master/Example.lua

Ping <-> Pong example:

require("socks");

local Cfg = {};
Cfg.IP = "123.123.123.123";
Cfg.Port = 1234;

	local data = UDPReceive(Cfg.Port, Cfg.IP);
	
	-- Check if we received anything
	if data == nil then
		return;
	end
	
	-- Read json
	local JSONIn = util.JSONToTable(data);
	
	-- Vertify that the json is valid
	if !JSONIn then
			return;
	end
	
	-- Send pong if we have ping or pong reqests
	if JSONIn.Ping then
			local Query = {};
	   	Query.Pong = true;

		 -- Send the packet
		local packet = util.TableToJSON( Query );
		UDPSend(Cfg.Port, Cfg.IP, packet, string.len(packet) );
  end

gmsocks's People

Contributors

azarus avatar

Stargazers

 avatar  avatar

Watchers

 avatar

gmsocks's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.