## Status of Multiplayer Mobile Networking

General discussion about LÖVE, Lua, game development, puns, and unicorns.
SmartGlassesMan
Prole
Posts: 14
Joined: Wed May 16, 2018 1:28 pm

### Re: Status of Multiplayer Mobile Networking

zorg wrote:
Sat May 19, 2018 7:56 pm

And again, you don't need to do anything yourself regarding Enet, it's bundled into löve, like how luasocket is. You just

Code: Select all

local enet = require 'enet'

and it works.
Ah. There must be something wrong with my sock.lua code then. I got an error about enet being nil, and I went down the path of thinking it was because I hadn't installed enet.

Thanks.

Code: Select all


-- server.lua
sock = require "sock"

-- Creating a server on any IP, port 22122
server = sock.newServer("*", 22122)

-- Called when someone connects to the server
server:on("connect", function(data, client)
-- Send a message back to the connected client
local msg = "Hello from the server!"
client:send("hello", msg)
end)
end

function love.update(dt)
server:update()
end


I must be using sock.lua wrong.

Thanks for the information!

zorg
Party member
Posts: 2502
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Status of Multiplayer Mobile Networking

I don't know any sock.lua, but if it's using enet from before 0.11 nightlies, then it might still expect enet to set a global variable (called enet) and expects it to work like that; it doesn't anymore, that was bad coding style. You can check and just edit it so it'll be a file-local instead.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

SmartGlassesMan
Prole
Posts: 14
Joined: Wed May 16, 2018 1:28 pm

### Re: Status of Multiplayer Mobile Networking

zorg wrote:
Sat May 19, 2018 8:09 pm
I don't know any sock.lua, but if it's using enet from before 0.11 nightlies, then it might still expect enet to set a global variable (called enet) and expects it to work like that; it doesn't anymore, that was bad coding style. You can check and just edit it so it'll be a file-local instead.
Nice. I'll try it.

4aiman
Party member
Posts: 248
Joined: Sat Jan 16, 2016 10:30 am

### Re: Status of Multiplayer Mobile Networking

Sock.lua is a great lib!

(what zorg said) True, the 11.x the "enet" global variable doesn't get registered automatically. One have to do

Code: Select all

local sock=require("sock")
Other than that you may want to double check the IP you're running server at. Or just use "*" to allow any IP.
With that in mind it shouldn't be too difficult to send some messages.

On a side note, you may want to learn about threads as sending some huge data (say, upon connection of a new client which doesn't have any cache stored) will hinder any other message processing.
What I did was:
- connect to a server, check for content updates
- if there are updates, the server answers with an IP:port of another server to connect to and creates it (the new server)
- the client then disconnects from the main server and connects to the given IP:port where it can easily get an update of any size
- upon completion, the client can re-connect to the main server
That ^ by no means is a perfect way to get some huge data, but it has worked for me so far
Anyway, people here will be able to correct me.
Cheers.

SmartGlassesMan
Prole
Posts: 14
Joined: Wed May 16, 2018 1:28 pm

### Re: Status of Multiplayer Mobile Networking

zorg wrote:
Sat May 19, 2018 8:09 pm
I don't know any sock.lua, but if it's using enet from before 0.11 nightlies, then it might still expect enet to set a global variable (called enet) and expects it to work like that; it doesn't anymore, that was bad coding style. You can check and just edit it so it'll be a file-local instead.
I think that worked to get past the first error.

I changed the following line in sock.lua

Code: Select all

require "enet"

to

Code: Select all

local enet = require "enet"

The server code in the above post now seems to run without any errors. Certainly no errors thrown yet.

Now, if I can just get past the client code error I'm getting.

SmartGlassesMan
Prole
Posts: 14
Joined: Wed May 16, 2018 1:28 pm

### Re: Status of Multiplayer Mobile Networking

4aiman wrote:
Sat May 19, 2018 8:25 pm
On a side note, you may want to learn about threads as sending some huge data (say, upon connection of a new client which doesn't have any cache stored) will hinder any other message processing.
What I did was:
- connect to a server, check for content updates
- if there are updates, the server answers with an IP:port of another server to connect to and creates it (the new server)
- the client then disconnects from the main server and connects to the given IP:port where it can easily get an update of any size
- upon completion, the client can re-connect to the main server
That ^ by no means is a perfect way to get some huge data, but it has worked for me so far
Big data is a bit beyond my current project stage (just starting) but that may be some good advice for later on.

Thanks.

ivan
Party member
Posts: 1394
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Status of Multiplayer Mobile Networking

zorg wrote:
Sat May 19, 2018 7:00 pm
SmartGlassesMan wrote:
Sat May 19, 2018 6:48 pm
No it's not, when it gets misinterpreted.
Sure, enet and luasocket are cross platform.
However, you are still going to need some sort of authentication -
which is usually handled through Andoid/iOS (I don't think you can interface with these from Lua/FFI).

SmartGlassesMan
Prole
Posts: 14
Joined: Wed May 16, 2018 1:28 pm

### Re: Status of Multiplayer Mobile Networking

ivan wrote:
Sun May 20, 2018 4:58 am

Yep, enet and luasocket are cross platform.
However, you are still going to need some sort of authentication -
which is usually handled through Andoid/iOS (I don't think you can interface with these from Lua/FFI).
Good point. Yes, there is much more to networking than just access to a low-level networking library.

They corrected my misconception about how to use enet, though.

Ikroth
Citizen
Posts: 70
Joined: Thu Jul 18, 2013 4:44 am

### Re: Status of Multiplayer Mobile Networking

SmartGlassesMan wrote:
Sat May 19, 2018 8:30 pm
zorg wrote:
Sat May 19, 2018 8:09 pm
I don't know any sock.lua, but if it's using enet from before 0.11 nightlies, then it might still expect enet to set a global variable (called enet) and expects it to work like that; it doesn't anymore, that was bad coding style. You can check and just edit it so it'll be a file-local instead.
I think that worked to get past the first error.

I changed the following line in sock.lua

Code: Select all

require "enet"

to

Code: Select all

local enet = require "enet"

The server code in the above post now seems to run without any errors. Certainly no errors thrown yet.

Now, if I can just get past the client code error I'm getting.

Thanks for reporting that, I just pushed a fix that exports enet as a local instead. I didn't like the global style before either. Let me know if you have other issues, I haven't done a full check since 11.0.

Pebsie
Party member
Posts: 137
Joined: Mon Nov 11, 2013 12:35 am
Location: Lincoln, United Kingdom
Contact:

### Re: Status of Multiplayer Mobile Networking

It's pretty much the same as Windows networking, you've just gotta be super conscious of data usage and dealing with network drop outs.

Here's a game I'm working on that is entirely network oriented that is going to be released on mobile platforms: viewtopic.php?f=14&t=85025&p=219410#p219410

It can be done and is being done!
Website: http://peb.si