2024-01-31 08:22:53 (edited by abdallah 2024-01-31 08:24:24)

hello.
I recently know that the asyncio library in Python supports building networking applications.
And dealing with it, with support for multiple connections and asynchronous server programming, is this good for using it in making games?

battle.net tag abdallah#22878 the new one because i lost my previous account
my facebook

2024-01-31 08:54:29

Probably. Depends on what your doing, but in general I'd say yes.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2024-01-31 09:17:51

I don't think pygame or pyglet supports it so that's the problem with doing that.

2024-01-31 09:33:47

So, with socket, is multi threading enough, or is there something else I should use?

battle.net tag abdallah#22878 the new one because i lost my previous account
my facebook

2024-01-31 17:20:03

Yes you can use asyncio.  No none of the game libraries support networking in any language because that's on you.  Run asyncio in a background thread--only one thread mind you, for everyone--and use queues.

My Blog
Twitter: @ajhicks1992

2024-02-01 18:30:41

I think asyncio would work, but it's really hard tofind actually good documentation that explains how to use it in my experience.

Blindgoofball
Founder and lead developer at Nibble Nerds
Where gamers are united!
https://nibblenerds.com

2024-02-01 20:51:24

There's a ton of official tutorials in the Python docs that do just fine.  It's one of the better documented and explained things out there.  The problem is that networking is hard, everyone expects it to be easy, the docs explain how it's hard, and therefore the docs are to blame, not it actually being hard.

Your choices for networking are don't, kinda sorta gloss over the hard bits with something like enet until the hard bits bite you hard, or learn something like asyncio properly.  Ultimately, though, getting bytes from point a to point b is the easy part anyway.

I mean technically something something threads something select, but going as far as using select yourself is the kind of thing where if you could you wouldn't be asking, so idk.  Like at the end of the day a lot of the time networking is along the lines of if you have to ask you're not ready.  Not always.  I know of a few exceptions.  But if you can't read the asyncio manual and go yeah this is how it goes together, you probably should focus on learning other things for a while (and that's not just about Python--if asyncio confuses you, all the other languages are as involved, sometimes moreso).

Grab a websockets library and use that, is my advice.

My Blog
Twitter: @ajhicks1992

2024-02-01 23:29:56 (edited by magurp244 2024-02-02 01:12:20)

I would classify network programming as intermediate to advanced, not necessarily because its hard, but because there are a lot of things you need to account for when writing good/stable net code. Its the kind of thing that you should probably only attempt if you already have a good grasp on programming already.

There's the basic building blocks, establishing connections over UDP/TCP, server/hosts, sending/receiving data, etc. which I would recommend learning first. Then moving on to more complex things like ensuring connections remain synchronized, dealing with dropped connections, lag/timeouts, etc. The specific type of network model you use, stuff like asynchronous lock-step and such, may largely depend on the kind of game your making, be it turn based, RTS, or FPS.

edit: Oops, should probably include security design as well. Remember: Never Trust the Client.

Depending you can either go with a centralized server run by yourself, or just stick to LAN and have people use something like Hamachi for internet play. And yeah, I've found the documentation on such things to be a bit on the convoluted/dry side.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2024-02-01 23:37:41

Well, networking is intermediate. But game networking requires developing novel ideas because there's no good open source options for such, and that's on top of needing the game to be efficient, and also have the networking be efficient both in terms of speed and number of bytes sent.  I think that pushes it over to advanced honestly.  If you can get away with http requests for your card game or something do that by all means, but things like Mist World aren't simple.

Websockets may be a good choice because contrary to the name you can also use them outside the browser, they handle splitting the bytes into messages and such, they can punch through firewalls like https does, and you can get at them from the browser should you ever want to (the browser cannot form raw tcp, it's websockets, sse, or bust).

My Blog
Twitter: @ajhicks1992