Network Multiplayer Template (Server X Thin Client) - WIP

After studying python network libs, I made this template (still work in progress !!).
This demo is already a fully functional example of a networked multiplayer game (using server X thin client architecture).

A brief explanation of the architecture is here
This demo is a 3D Pong, where two players can be at diferent computers in the internet

How to test in one machine:

  • Open and run the server first. It will start listening two connections. Blender will freeze because this is a blocking operation. Let it opened. (Multi-threading python is causing Blender crash in my machine)
  • Open another Blender with the client and run it. This Blender will connect via TCP to the Blender server. Again, this new Blender will freeze because we need to wait the second client/player to start the game (this synchronization is done by blocking TCP reads)
  • Open a third Blender with the client. When you run it, this third Bender will connect to the server and the game begins !!! Try to put the windows side-by-side to see the fast syncrhonization achieved using UDP messages
  • Use W, S, A, D keys in the two clients to see how the state is spawned to server and the clients. Ball physics is spawned automatically !

For now, to test in networked machines you need to change the IP adresses in the scripts. Remember to always start the server first ! The network protocol is the python serialization function in the module “pickle”.

To python prgrammers: Discover how one client can “cheat” the server in this example

(I think you really need python installed to this work)
Server blend: http://uploaded.to/?id=we92g8
Client blend: http://uploaded.to/?id=m0gmfg

I’ll try a tutorial on this when completed.
UPDATED: Server now tracks score and clients are textured and has shadows. Now I’ll try to make multi-threading connection works

Attachments


Yes for it to work you need Python 2.5 (as you do for mine). I also noticed that blender freezes if the server is a .exe, you should make the server just a Python module, that way you can just run it as it’s own console no need for blender.

Hmm, maybe you could help me with sycing zombie/door/bullet (from a gun :p) movement?

Thread: http://blenderartists.org/forum/showthread.php?t=100617

Please upload elsewhere! I hate rapidshare you need to wait an hour between downloads!

Are you sure about that? I just downloaded both? Took 15 secs…

UPDATED: Server now tracks score and clients are textured. Now I’ll try to make multi-threading connection works

[Oups… Textures where not packed]

Server blend: http://uploaded.to/?id=i4jwnm
Client blend: http://uploaded.to/?id=ra9u5f

Hmm, maybe you could help me with sycing zombie/door/bullet (from a gun :p) movement?
I’ll look it.

It works great on my PC. I don’t have a setup to be able to test it on a network right now, but I’m curious to hear what kind of results it give.

A couple of things:
You forgot to pack the textures (looks nice in the screens, though).
The game currently doesn’t recognize when one client quits or the connection is lost, so the remaining player might continue for a little while wondering if the other person is still there.

You forgot to pack the textures (looks nice in the screens, though).
I noticed the textures where not packed. Just uploaded a packed version now.

The game currently doesn’t recognize when one client quits or the connection is lost, so the remaining player might continue for a little while wondering if the other person is still there.
I know. The server must detect when one client disconnects and send a special message to the remaining client signaling the end of the game. These synchronization issues are the ones that demands more coding. Also, I’m having problems starting new python threads (the threads don’t start or Blender crashes)
I will pack this simple version to people study and will try to implement the synchronization code.

It works fine for me with blender 2.43 and python 2.4. Its really cool, and if you made a tutorial, you would be awsome in my book.

God this might be exactly what we are looking for!

could this be expanded to like 4 players?

p00f and I are planning on a chess game, where the pieces settle the the disputes in a 3rd person death-match in various arenas,
(based ancient commodore 64 game by the first Electronic arts, Archon, and Archon 2)

Man, I got to see if we can try this at work on the LAN!

thanks for making this :smiley:

What do you mean?

Hey, very cool.

Sadly i was not able to play. I click inside the blender clients and “wasd” doesn’t work… But Blender tell that “conections” are ok (server was able to “catch” clients). :S

Using python 2.5 and Blender 2.44

Later i will try Blender 2.43 and python 2.4 like Ragshan did.

Congratulations for the excelent work!

could this be expanded to like 4 players?
Yes. It’s all about plain python programming. The server can handle a list of clients (with sockets and addresses), and send messages to all clients in the list.
One important first step is define the comunication protocol between client and server (put it on paper to not get lost). I’ll put this in the tutorial
I tried it in a LAN (actually two PCs connected by a cross-cable), and worked fine

What do you mean?
I mean I will try help with your problem later (Sorry … Read my signature)

Great! :wink: I really hope you can help.

Blender also froze for me and never worked, i’m using blender 2.44 & Python 2.5.

I followd your directions but i still cant get it to work, all that happens is the server runs but then its says invalid syntax socket?

Can you post the complete error message ?

OMG this is just waht i need make raelly cool mmorpg… i am making team will people pls sign up help make my game? Thanks!!!111!!!111 lolz

Just kidding…
This is really great morgade (although I don’t think I can test it), thanks a lot for this excellent contribution to the BGE community. This makes a great addition to Social’s FPS and Walkthrough templates. Maybe in the future we’ll have more templates and therefore fewer stupid questions? All we need now is the “raelly cool game” template…

OH NO…PlantPerson = noob:confused::eek:

PHEw:eyebrowlift:

This multiplayer template is a great idea! as far as i know this is the first time it was made( I know it was thought of more than once). Also, nice choice of pong for a template, its simple and anyone who wants to learn networking in blender can easily do so with this.

hmmmm … I think that you mised the BZoo (alias BlenderZoo) template, which is working pretty well allready !

the only thing is that I never been able to have the server noticing the disconnection of players when running on Linux, so I left it where I was with it last year …

But I think it could be corrected by some python guru out-there …

This worked Perfectly on my computer. Great work. This is REALLY GOOD. Super fast framerate too.
It seems to work on blender 2.42a and blender 2.43. (with python 2.4).

When I try to run it from my computor ro my bros with the server runing on mine it gives him a massage in the console saying “no attebte ‘myid’” what do I do?

Cool! I always wanted to figure that out.