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->HostNetwork exerts a good efficiency outside the lan network in online games?

Author
Message
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 24th Jun 2023 03:53 Edited at: 24th Jun 2023 03:54
Hello everyone, I'm studying a lot about online multiplayer games, and I'd like to find an effective way to create them, I had a question if it's effective to use the commands Network -> HostNetwork and the like to create them, would anyone know how to tell me more about the efficiency of it? if it is possible and it makes sense to use in multiplayer games that require some speed like fps, rpge etc ....
everywhere says that udp is the right one. but what about agk's multiplayer commands?

Thank you all for the attention.
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 25th Jun 2023 20:41
In general for fast paced/real-time games, UDP is the way to go for performance (the 'CreateUDPListener/SendUDPNetworkMessage' approach in AGK/S). The 'HostNetwork'/SendNetworkMessage' approach in AGK/S is TCP, which is good for guaranteed messages like text chat exchanges, setting exchanges, scores, player list, and/or other elements that don't need to be updated at a rapid pace. TCP can also be good for turned-based games and other approaches that may only need occasional state/move updates. So ultimately, you may want to blend the two, TCP for connecting and critical packets, UDP for player data/gamestate. Or stick to UDP exclusively and design a guarantee mechanism for the most important packets as may be needed. With UDP, you will need to keep track of the IP address and port for every player you want to send packets out to. So that is something you'll need to be aware of using that protocol. You also may want to come up with your own player list management system, depending on if you design a client-server or peer-to-peer model. Easier to keep track of each IP and port for every player that way anyway. But that's more on the design side of things. To get back to your original question, if your game is real-time/FPS/action, you'll likely want to utilize UDP exclusively or at least incorporate it into the network connection for optimal packet transmission performance.
EdzUp
21
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
Posted: 26th Jun 2023 07:51
For me the best way has been to have a ID value in the packet so the system can keep track of last packet processed so to not have charactera jerking all over the place due to processing packets in the wrong order. UDP is fastest but unreliable, TCP is more reliable BUT this does not give 100% reliability as connections are vastly different in capabilities (for example dialup connecting to broadband servers etc).

Another thing which i learned early on was dont spam packets send maybe ten or twenty a second max and have the program tween between the two to give reliable player experience otherwise you are going to overload your nerworking system and cause a bottleneck there.
-EdzUp
Patreon: https://www.patreon.com/EdzUp
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 28th Jun 2023 04:07 Edited at: 28th Jun 2023 04:07
Thanks to SFSW and EdzUp for clarifications.
but I confess that it is still being quite a challenge to try to create a server and client for an online game using AppGameKit ... both in tier 1 and in tier2 , it is being very painful, do you have any examples for me to have notion of how to create something similar to a UDP Client that sends and receives information from a server on a specific port?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 28th Jun 2023 12:07
OK I have been studying this today and I get the setup, I have 2 apps talking via UPD and a deeper understanding of how this function set is implemented

UDP is NOT a client/server system its 2 independent listeners that send data to each other this poses some rather large limitations but I can overcome this by adding a data class and logging the incoming connections on the server, save the IP address and assign a client id then the server knows who to send updates to, a quick solution but not a good one, the problem with this is as there is no direct connection I can not directly check for a disconnect unless I ping all known connections and wait for a return ... and run the active messages and handle all the other tasks my viral game would demand! , again a quick solution but not a good one (unless I am missing something in the function set but I see no way of checking if a UPD connection is valid or any way to check if a message made it to its target without replying ..... thats 3 messages for every 1 sent ... that is not going to work)

so that being said, and as my needs would probably demand ....

this system also needs a tcp connection to run in tandem for the mundane stuff, login, ping, chat server ... low priority stuff and use the UDP for position updates and real time data that needs to be moved fast, this way I can utilize the client/server aspect of the tcp connection to have a more robust system and the speed of UDP for the realtime data ......

Anyone know of any free VPS I can pipe into for remote testing?
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 28th Jun 2023 15:16
this is incredible, I had already thought of using tcp and udp as a two-way street, it would be quite effective for games that require network reliability.

is c++ compatible?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 28th Jun 2023 16:21
Its all C++, Tier1 is great dont get me wrong but I have become a custom to C++ now so I'll stick with it, the more I code, the more I learn, the more I can code

just so you know where I am going with this here is my server code so far, its by no means complete and barley functional but will show my way of thinking


and example usage, I am aiming for simplicity, the above class does the heavy lifting freeing the "App" functions to take care of UI and other server logic, AI, Bots etc etc


Now i just need to work on the client interface and can start trashing out a proper messaging system
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 28th Jun 2023 22:45
For a Tier1 example of NAT punchthrough for UDP, I posted this a while ago: https://forum.thegamecreators.com/thread/228937

And it can be reduced down to just a basic connection, skipping the STUN server and punchthrough to just connect over UDP (signal confirmation check included). But that's if you just want to use UDP only. UDP is primarily a 'connectionless' type protocol, packets are sent regardless of whether a handshake between systems is done or not. Only a listener on the other end will or will not receive the packet, so handling connection state (ie delay/timer checks for lost packets) and other related elements all need to be managed by the code if you stick with UDP only.

As mentioned, TCP with UDP can be a preferred way to go and offers several advantages. The 'Getting Started' example included with AGK2 in 'Projects\Multiplayer\GettingStarted' is a pretty good Tier1 example of just getting a basic connection and gamestate system in place using TCP. You can then just add the UDP side of things onto it using a different port to transfer the gamestate side of the data for improved performance.
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 29th Jun 2023 02:14
I confess that I'm also getting quite used to using agk with c++ , and you've given me an excellent insight into how to use sockets in agk.

Thank you very much for the knowledge that you are passing on to me.
PartTimeCoder and SFSW
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 29th Jun 2023 13:24
its somewhat shameful of me to admit that in my 3 decades of coding I avoided C++ like it was a virus, my experience with C gave me a phobia of unmanaged languages (anyone that knows C should understand that), but my fears were unfounded C++ is not the demon lurking in the dark that
I Imagined it to be and after many 100's of hours I have a firm-ish grasp of what the compiler expects from me .... but, learn more every time I open the IDE.

That being said my examples are going to start getting quite complex with lots of sub classes managing various parts of the game especially on the client side so I will show now the basic setup and rather than post long threads of code I will just github the entire project

https://github.com/PartTimeCode/AGK-Network

Download the repo and unpack

Launch AppGameKit Network.sln, and compile AppGameKit Server and AppGameKit Client, ignore AppGameKit Common this is a static library that holds stuff shared between both client and server.

Open the "Final" folder, launch the server, then launch 3 or 4 clients and see the info change in the server output

the server detects new connections and disconnects (check the code for how)

I will keep pushing to this repo untill we have a small game type system but it would be helpful to you if you saw the system now before it grows and maybe this is enough to get you started?
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 29th Jun 2023 15:45
the way you did it was incredible, even a layman like me can get an idea using this example ... how do you send messages to specific clients or even to all?


I am very happy that you can share this example.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 29th Jun 2023 16:31
I am working on that now

I first have to understand how TCG have implemented the socket code and after studying the source and it seems fairly intuitive, all clients have access to all aspects of the connection data, each client knows who is connected without having to query the server and a bunch of functions are setup to handle variables that are shared across all clients, it all seems fairly easy to setup a game but this system is intended for the server (host) to also be part of the game world so I am wondering if its just better to write our own socket system or utilize this behavior to our advantage and have the server client be more of a "super client"

I do foresee a problem though, most VPS are intended for remote access and dont have graphical capability rendering this whole thing useless in a production environment unless hosted on a system with graphical support.

if the window cant open, the server simply cant start, it should be a console application so I am thinking maybe you had the right idea in the first place by writing the server in PureBasic .....

for now I will continue with this example because its a good learning exercise but I dont think its going to power the next WOW or EvE online!
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 29th Jun 2023 18:46 Edited at: 29th Jun 2023 18:52
ok I got a bit side tracked on this a little but it might be worth it

the issue I previously mentioned in PM about not being able to get PureBasic and AppGameKit to "talk" was because I was using the wrong functions, a direct socket connection works just fine I have 2 way communication running with a handful lines of code but it needs wrapping up into something usable

I think given the previous mentioned issue regarding VPS this approach would be the best

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Attachments

Login to view attachments
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 30th Jun 2023 00:00
dude, you are a genius...
this is pretty awesome.

A few years ago I looked for help on the purebasic forum, to get the answers coming from agkSocket : https://www.purebasic.fr/english/viewtopic.php?t=70261

but from what I looked at your code, it makes it too easy.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 30th Jun 2023 05:02
well reading the values in PureBasic is easy because PB intelligently splits the data into the chunks it was received but AppGameKit does not seem to do the same it just sends a slab of data, the first message is fine but when I made functions and spammed the client only the first string makes it then the whole data structure loses it!!

I gave it a few hours of debugging and walked away, I will revisit it tomorrow maybe mk-soft was onto something with adding a null to the packet, when I stepped into the code with the debugger the right amount of bytes were in the buffer but when I tried to read the int for the next message ID i got garbage so there is a buffer misalignment somewhere.

but at least now we know it can be done, your original idea of having a PureBasic app as the server and the client in Tier1 with a PB network plugin is starting to sound like a good idea..... its all native functions then and none of this nonsense! lol

Virtual Nomad put me onto Photon a while ago I gave it a quick look then but it baffeled me a bit, having another look now I understand a lot more, most of the info out there is for Unity but the C++ examples cover most things, there is a free tier for testing and if a game draws attention it would be worth renting time ..... many pies! lol
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 30th Jun 2023 18:54 Edited at: 30th Jun 2023 18:57
ok this is the TCP part, I will figure out the UDP later


C++, complete example, open a new agk template and paste this code


PureBasic, same, open a new file and paste the code


I wont go into detail how it all works the code for both is heavily commented, its a good base for a TCP socket server/client system, I will work on adding some more "game" type logic to it later for now I am taking a break, I been coding 6 hours lol
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 1st Jul 2023 05:20
this example got me really excited by the possibility. I thought it was a lot of work to implement the socket from agk to purebasic . I don't even know how to thank you for all your help and effort.
I tested it and it worked perfectly.

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 1st Jul 2023 17:17 Edited at: 1st Jul 2023 17:37
Not perfectly!

As I am expanding this to be a proper game client/server setup I am noticing 1 or 2 bugs in my code, first and foremost is this

bool cGameNetwork::IsConnected(), in the case where the server is not running its reporting that its connected

change this


to this

.
GetSocketConnected wrote: "Returns 1 if the specified socket is connected, 0 if it is still in the process of connecting. If the socket becomes disconnected or fails to connect then this will return -1"



Edit:

Actually a better way to do this is ....


and check the connection like so


but cGameNetwork::IsConnected() is being called in the network class so I'll have to edit those functions to

AS I move forward there will probably be 101 things I'll have to change to turn this from basic example to functional system!!
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Arch-Ok
AGK Developer
4
Years of Service
User Offline
Joined: 11th Jul 2019
Location: Bursa/TÜRKIYE
Posted: 2nd Jul 2023 15:46 Edited at: 2nd Jul 2023 15:46
Using TCP sockets worked for me;

https://play.google.com/store/apps/details?id=denklem.v0000

P.S. Game GUI will be updated in a few months, I guess...
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 5th Jul 2023 19:40 Edited at: 5th Jul 2023 19:41
I use sockets, But i also like to talk to python and other devices as well as games. Here is a socket server. it is set up for tcp atm but just add a second udp listener and add it to the message queue. here is the general gist of it though had to strip out alot of custom stuff thats running my mmo server so it will not run but may offer some good examples

SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 10th Jul 2023 18:28 Edited at: 10th Jul 2023 18:29
and about ping in ms ? Arch-Ok

are u using socket tcp ?? smerf
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 10th Jul 2023 18:31 Edited at: 10th Jul 2023 20:18
I'm trying to check the ping in milliseconds, look at the result I'm having: https://prnt.sc/HLyTSh5kXzXR ( (I don't understand why the response is taking many milliseconds according to the screenshot) )

every 5 seconds a message is sent, and the server responds.
every time the message is sent the timer is reset and timed again, when I receive the message from the server, I get the milliseconds with : agk::Getmiliseconds() to get the time in ms that it took until the response reached the client .

Is this the right way to get the ping?
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 12th Jul 2023 19:49
Thought I replied to this already but i guess not. If your connection is local and it is taking a long time then it is limited by sleep or sync command. a server should run headless as possible without an interface/gui. so if you are using syncrate() on your server dont. use a loop scan rate n run your sync off it. so if loopcounter=400 sync() or render swap this will allow 400 loops before it tries to print to the screen good for hitting a few hundred clients a ms with data. Also using the round robin method help alot. You process 1 message per player per loop so not looping through each clients messages and then the next client. I recommend a message queue. You are checking correctly for milliseconds. and yes im using socket tcp and udp.

Login to post a reply

Server time is: 2024-05-04 07:09:05
Your offset time is: 2024-05-04 07:09:05