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.

Newcomers AppGameKit Corner / is it possible to nest network messages for multiplayer?

Author
Message
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 19th Jul 2018 03:04
So I finally got my players to load the world, and we are moving right on to the next obstacle. I am trying to learn to control multiple players through loops and network messages.


It was working great, until players 3 and 4 joined. then there were just a bunch of ghosts running wild and players blinking. I think the messages received are going to all players, and not the respective players. Does anyone any idea of a good way to achieve this, or should i just make a giant batch of messages going through each player and send once? Thanks in advance for any help!
One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 19th Jul 2018 08:40
I spotted this "i <> GetNetworkMyClientID(NetworkID)" at line 53 in your snippet above, the Network ID usually start at 100001 or something like that, not 1. This, "for i = 1 to GetNetworkNumClients(NetworkID)" will start from 1 to the number of players (like 2, 3 or 4) and will not go as high as the value returned by GetNetworkMyClientID().

Another thing, are your host and clients running on the same LAN? This could also give some problems when connecting through an IP address and a port number over the internet. The router will not know which computer to send data to and something like your ghosting thing running around could happen. You can setup code to check if the host and client are on the same LAN and connect through LAN instead of the over the internet. You can check this out from the help files https://www.appgamekit.com/documentation/Reference/Multiplayer/CreateBroadcastListener.htm Using a broadcast listener you can find AppGameKit apps on the LAN. I setup my network name with something unique so that the app can see the difference between hosted sessions.
13/0
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 19th Jul 2018 10:23
I think you need to send which player is sending the data - right now it looks like its positioning all 3 of the other players based on the message it receives but as it doesn't know which char it is supposed to be positioning it places them all in the same place?

Works great for 2 players because there's only 1 possible player to place... Not that case when there's 3 others
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 19th Jul 2018 12:30
I intended this game to be used as a LAN multiplayer, as I assumed it would be more simple to code than an online game. My other concern for player over the internet was lag (possibly created by my inexperienced and inefficient use of commands XD). When I use getnetworkmyclientid it returns 1 2 3 4 respectively. I can try using a listener, but I've also never done that.
I've done quite a bit of searching the web for more info about the network messages, and there doesn't seem to be much.

If I told all clients to send their message to the host only, and made the host push out a master message containing all players position and angle, that might take care of the duplicate messages, but how would I handle identifying which player each message came from, to know how to return them for the corresponding sprites?

Smallg, maybe if the first message sent is i, I can change the statement underneath get network message to only set position of that player. I will give it a try! Thanks for the info guys. It would be cool to have the online game play option. Maybe I'll try that once my feet get a little more wet.

One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 19th Jul 2018 13:00
Quote: "When I use getnetworkmyclientid it returns 1 2 3 4 respectively"


Sorry, I was thinking on Network ID for the network itself. But still, as smallg says, you should have a player ID in each packet. You can have the host assign new IDs as clients connect.

And on the lag, you can use socket commands and make tight messages. I have some code where I send Player ID (1-5), X (1-1280), Y (1-720) and Direction (0-359) in just 4 bytes, this gives less lag but you gotta have some tight code because X 1 to 1280 would normally be two bytes alone, Y 1 to 720, another two bytes, direction 0 to 360 two bytes more and player ID 1 to 5 would be one byte, 7 bytes in total. But I have squeezed it down to 4 bytes for each position packet. So 5 player should be 35 bytes for all player positions but is instead 20 bytes, not a big difference but I think it helps. I can give you some details on how to achieve this if you want and are going into socket commands. Socket commands let you add as little as one byte to a packet whereas the regular multiplayer commands will only let you add a 4-byte integer as the smallest amount of data in one go (8 bytes if they are 64-bit integers).
13/0
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 19th Jul 2018 16:13
Unfortunately, I know absolutely nothing about socket commands. This is a good opportunity to learn about it though. I will check it out after work. I can send you the full program zipped in an email if you would like to see what I'm trying to do. I added a message integer to identify the player sending the message, to help with receiving the right commands, but I'm still getting an invisible player and a player Sprite that doesn't move.
One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 21st Jul 2018 08:37
Okay, I can have a look
13/0

Login to post a reply

Server time is: 2024-04-20 09:14:16
Your offset time is: 2024-04-20 09:14:16