Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Networking

Local Multiplayer

How to get the best of multi player experience

Local Multiplayer

Postby DoctorPepper » 17 Aug 2012, 13:51

So in theory, one could start a local networking session with
network.createServer ( network.kDefaultServerPort) or .kBluetoothServerPort

other players can join the session by calling network.searchForServers (network.kDefaultServerPort) (Which will loop through all ports?)

if a player finds a server, network.getStatus() will return server.kStatusConnected
Then you have to set Current server by network.setCurrentServer ( ... ? how to identify a server name, if several are present? )

Then you can simply use user.sendEvent to communicate with other players.

So, does this only work for bluetooth and Lan cables, or will it also scan the local wifi network? If so, would port forwarding be a problem? What if one of the players creates a hotspot and the other one connects.
How good is a bluetooth connection? is it even suitable for 2-4 player game?

Basically, i want to add an option for friends to play against each other, ideally without any network connection, as long as they are in close range. (at home, school, bus, train etc). I am also aware that not all android devices support bluetooth, so multiple options is a huge plus.

How heavy is network.createServer() on cpu and the battery? Would it be acceptable to do it every time a player starts the app, so he is automatically visible to everyone on the same network?

Will searchForServers only search for an exact copy of the app, or is it possible to connect different devices with different binary builds? (or does it use the signing bunle identifier or signing identity from Authoring tool?)
User avatar
DoctorPepper
Platinum Boarder
Platinum Boarder
 
Posts: 474
Location: Belgium

Re: Local Multiplayer

Postby Fraser » 17 Aug 2012, 14:41

Hi,

For some quick testing of devices/net configs here is a run-ready STK nicox originally posted:

http://developer.stonetrip.com/Download/Misc/TEST_SearchForLANServer.stk

I built it for ios & android and ran on PC, they could all host and join sessions via my LAN WIFI router. I used 5 different mixed devices and got good connections trying every one as host.

Be warned, search takes a LONG time as it enumerates address space. This could be reduced with multithread search, maybe 2.0 will have this?

Ports need hard coding, same on all app instances. you could include user defined port that defaults to known number. players would then be responsible to set same port#.

If more than one server is availabe (>1 host) then the players are screwing up, only one should initiate host. others should join. No point in initiating host on app start, you need to give players "host" and "join" buttons, they need to agree verbally who hosts. Person with most powerful device should host.

Port forwarding should not be an issue within LAN.

If you get results then dig deeper into the multiplayer example STE (something I have yet to do).
Fraser Ashworth,
https://www.cortex7.net
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1086
Location: Europe

Re: Local Multiplayer

Postby DoctorPepper » 17 Aug 2012, 16:04

My reasoning behind multiple hosts:

When i was in highschool, we used to open ports and allow p2p connections on the school's server and play counterstrike against each other. In college, they didnt block pear to pear stuff like torrents, so i assume that it would also be possible, but who knows, i know very little about networking.

Today, in most classrooms everyone sits on the same network, everyone has an android or an iOS device, 4 people want to play a game, max player count is 2, so you need 2 "servers.
Or, subject A is bored with calculus, want to shoot some zombies. On initialization an app hosts a server. Subject B on the other side of the room also wants to waste time and go achievement hunting, but is not aware that anyone in the room has the app. So he scans the network (which would take forever?) and is able to connect to A. At this point, he can push a request for a multiplayer game. Or send a gift bag, unlocking collaboration achievement and generally making friends, wink.

Anyway, atm i am totally fine with someone creating a hotspot, letting the other player connect, communicate the port number and going with that.
User avatar
DoctorPepper
Platinum Boarder
Platinum Boarder
 
Posts: 474
Location: Belgium

Re: Local Multiplayer

Postby Fraser » 18 Aug 2012, 00:27

Search time depends on the hosts assigned IP; From sniffing the LAN host/client sample I see 2 threads and one socket used for the search with a 1 second timeout. so worst case is around 4 minutes to find a host. best case 1 sec.

On a desktop machine I would spawn multiple (64 or more) concurrent socket threads for the search. but on some mobile devices that may not be feasible. One scheme that shiva should implement (even with one socket) is searching around (above and below) the clients own LAN address lobyte.

P.S.
shiva allows many players with one host.
Last edited by Fraser on 18 Aug 2012, 01:18, edited 2 times in total.
Fraser Ashworth,
https://www.cortex7.net
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1086
Location: Europe

Re: Local Multiplayer

Postby Fraser » 18 Aug 2012, 00:44

I just reread your post and get what you are saying, every game instance starts a host on startup, ready for unscheduled multiplayer action. Yes I suppose that would work.

In which case you would only need a "search" button; when a hopeful player pushed "search" it would kill his own server and hunt for other hosts. If none found the search stops and his server restarts.

I dont think having a server listening would cause noticable game slowdown.

It's a good idea, you could market it as "Active LAN play plus - Always ready for action" or something.
Fraser Ashworth,
https://www.cortex7.net
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1086
Location: Europe

Re: Local Multiplayer

Postby DoctorPepper » 18 Aug 2012, 09:50

I am mostly conserned about battery drain. I guess i could test it by taking a fully charged android device, and leaving it in the loading screen for an hour. Then doing the same while hosting a local server. Each time checking the battery stats.


Active lan plus, looks interesting to me, mostly because you could interact with nearby people, like a micro social network, with your actual social environment. Also, if made multi platform and add an ability to benefit from gift bags etc, students and co workers might be more willing to recommend a game, if they know that they will get ingame benefits.

Thats how ive downloaded Draw Something. Several people were playing it during the class, recommended it to me, so they could earn coins, ive showed it to several other classmates on the same day, and before i knew it, 10 out of 40 students were playing. Then i went home, where my gf said, have u heard about this drawing game?
User avatar
DoctorPepper
Platinum Boarder
Platinum Boarder
 
Posts: 474
Location: Belgium


Return to Networking

cron