Skip to content

Commit

Permalink
Added dependency to defold-luasocket
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Dec 6, 2017
1 parent b252f2e commit 4a622b1
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 483 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ I often get questions about networking in Defold from our forum users. Sometimes

Luckily for us Defold comes bundles with the excellent [LuaSocket](http://w3.impa.br/~diego/software/luasocket/home.html) library. With LuaSocket it is fairly trivial to create TCP and UDP sockets. Here's a bare-bones TCP socket example:

local client = socket.tcp()
client:connect(server_ip, server_port)
client:settimeout(0) -- non blocking socket
client:send(data) -- send data like this
local response = client:receive(*l) -- receive a "line" of data like this
```
local client = socket.tcp()
client:connect(server_ip, server_port)
client:settimeout(0) -- non blocking socket
client:send(data) -- send data like this
local response = client:receive("*l") -- receive a "line" of data like this
```

The above snippet of code, some reading of the LuaSocket documentation and perhaps a couple of Google searches will get you quite far, but some concepts like peer to peer discovery is a bit trickier. The goal with this project is to collect some useful Lua networking modules that can be used either as-is or modified to suit your needs.

## Requirements
Most of the code can be used in a stand-alone version of Lua with the only requirement being LuaSocket. In the modules provided here I `require("builtins.scripts.socket")` which is equivalent to [socket.lua from the LuaSocket library](https://github.com/diegonehab/luasocket/blob/master/src/socket.lua).


## Installation
You can use the modules from this project in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your game.project file and in the `dependencies` field under `project` add:
Expand All @@ -24,6 +26,10 @@ You can use the modules from this project in your own project by adding this pro

Or point to the ZIP file of a [specific release](https://github.com/britzl/defnet/releases).

DefNet also depends on additional files from the LuaSocket repository, not currently provided by Defold. In order to use DefNet properly you need to add a dependency to the defold-luasocket library project as well:

https://github.com/britzl/defold-luasocket/archive/0.11.zip

## Included modules
### Peer to peer discovery
The `defnet/p2p_discovery` module can be used to perform peer to peer discovery using UDP sockets. The basic idea is that an app sets itself up as discoverable and starts sending a broadcast message on the network. Other clients can listen for broadcasted messages and get the IP of the app that wishes to be discovered. This is how an app can set itself up as discoverable:
Expand Down
2 changes: 1 addition & 1 deletion defnet/p2p_discovery.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--- Module to perform peer-to-peer discovery
-- The module can either broadcast it's existence or listen for others

local socket = require "builtins.scripts.socket"
local socket = require "socket.socket"

local M = {}

Expand Down
1 change: 0 additions & 1 deletion defnet/socket/README.md

This file was deleted.

307 changes: 0 additions & 307 deletions defnet/socket/ltn12.lua

This file was deleted.

Loading

0 comments on commit 4a622b1

Please sign in to comment.