Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / multiplayer -- 2 player only -- way to manage host joins first?

Author
Message
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 9th Dec 2016 13:41 Edited at: 9th Dec 2016 14:56
To start with a basic multiplayer program I built a 2 person multiplayer game where each player "takes care of itself". I mean once the host and the client are determined, then the host is in control, I understand that...(but if it wasn't for the difference between host and client, both players would send network data equally)

based the code on the Newsletter https://www.thegamecreators.com/pages/newsletters/newsletter_issue_147.html#5
and the example codes from Lucas Tiridath (thanks Lucas!)


is there any way instead of having a Host AND Client button I could have just: "Join network"? and then I could determine the Host?

Tks
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Dec 2016 14:34
hmm, if booth start as host and booth join network the first player starting the game from lobby can be the host.
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 9th Dec 2016 14:57 Edited at: 9th Dec 2016 15:10
by game lobby you mean what?

if two hosts are created how is the host supposed to change the other to the client? (without creating and using a internet server---strictly peer to peer on wifi)

---------------------

client try to connect a few times if fail create a HOst?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Dec 2016 15:08 Edited at: 9th Dec 2016 15:10
game lobby is a meeting point where you can see the player list.
i guess HostNetwork and JoinNetwork gave you a different NetID.
this id is used in SendNetworkMessage

if you connect to a host, yes then you can use it.
this try connect or be a host seems a good idea.
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 9th Dec 2016 15:12 Edited at: 9th Dec 2016 15:27
So what you are saying is that I can't do it without php and and a domain and a server

I just want to connect wifi on wifi without declaring the host first (edit: in case the other player presses client first instead of host)

shouldn't it be like "IF GetHostExists(name of host,port)"?

I would also like to extend this to IP... shouldn't this be an option or is it something I am missing?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Dec 2016 15:27 Edited at: 9th Dec 2016 15:28
my idea was crossed over.
app1 start host
app2 start host
app2 try join app1
app1 try join app2
booth have a list with two players.
if one app click play button you can send a message that the other app close the host and using the join connection.

i think i would also use start as client and if can not connect to a host than create a host.
if you just will play with a friend at home inside your lan it should be ok.
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 9th Dec 2016 15:29 Edited at: 9th Dec 2016 15:33
what command do I use to check if I am looking for other hosts?


shouldn't it be like "IF GetHostExists(name of host,port)"?

I would also like to extend this to IP... shouldn't this be an option or is it something I am missing?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Dec 2016 15:35 Edited at: 9th Dec 2016 15:39
Broadcast commands should do the job inside a LAN.

connect from internet is special, you need port forwarding in router and public ip for a pc game.
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 10th Dec 2016 08:27
Tks!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Dec 2016 10:20 Edited at: 10th Dec 2016 11:13
my test today
idnet=JoinNetwork("MyGame","Player2") this give allways a id
active=IsNetworkActive(idnet) //it returns 1 if no host exist because JoinNetwork continues in background and try a connection ...

it was not possible to send data via broadcast between two agk apps^^ !?

AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 12th Dec 2016 13:21
are you having this problem where JoinNetwork always creates an external pop-up (saying network connection failed) if it cannot connect?
Is there a way to turn this off?

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Dec 2016 18:02
no me not had this pop up.
after how much time this pop up appear?
did you set any error level or had updated to .22 ?
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 14th Dec 2016 10:09 Edited at: 14th Dec 2016 10:12
JoinNetwork "failure" always creates an external pop up which currently can't be controlled
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Dec 2016 11:25
at the same moment you call command JoinNetwork ?
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
thoromyr
7
Years of Service
User Offline
Joined: 14th Dec 2016
Location:
Posted: 14th Dec 2016 13:44
I just recently did a small app that is essentially peer to peer. The game plays by itself, but anyone on the local network can join another game by typing "N". There is a 4-second hitch if there is no other game on the local broadcast as I did the network timeout in a loop separate from the main game -- but failure doesn't produce an external prompt.

So the app knows if it is running as client or server there are two network identifiers. On startup the app calls HostNetwork() and stores the result as srvNet. In the main loop it always enumerates clients using GetNetworkFirstClient() and GetNetworkNextClient(). It knows which client is itself via GetNetworkServerID() (though in practice it is always id=1 because it is always the first to join its own network). So the server knows when there is a client because it is able to get a clientID other than its own. It then bothers sending and receiving messages.

If the app tries to join a network it calls CloseNetwork(srvNet) and then sets srvNet = 0 before doing JoinNetwork() -- which result, if successful, is stored as cliNet. So if cliNet is > 0 it knows it is a client and sends and receives messages.

Although, using local variables proved to be less problematic than messages. Those you can always set as server or not, then if cliNet > 0 read from them.
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 15th Dec 2016 13:59
I didn't realize "message" was a command. It is in the functions communications.agc from the tutorial. HEHEH sorry my bad!

Thanks for the help Thoromyr too!

Should have enough to get it going once I sort it all out now



Login to post a reply

Server time is: 2024-11-24 22:50:18
Your offset time is: 2024-11-24 22:50:18