Creating a Server for a (Blender) Game - updated tutorial

Well, here is the link: Creating a Server for a (Blender) Game
The updated tutorial was too large to post on the forum so I moved it to my website.
Here is the introduction to the tutorial:

This tutorial will go over how to create a server in python (it doesn’t matter what language your server is made in but python will benefit the Blender user), make the server communicate with our client (being the Blender game) and setting up our game to run online.
The tutorial is python heavy so before reading make sure you know some python (this tutorial is written for python 2.5x).Even though this tutorial is written intended for the Blender user the techniques are still beneficial and will work for any other application.

Enjoy it and post questions if you have them.

well, i don’t really get it but good work! i was under the impression servers had to be purchased… don’t they? I don’t really get the internet :smiley:

Thanks. I’ll be keeping an eye on this thread.

Here’s another one I had bookmarked on network gaming:

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

Hey, is LAN networking possible?
I have several PC’s at my house and all are linked up on a LAN network. We play games like Starcraft:yes: together, so why not a Blender game?:rolleyes:

I think so, you have to make the host in blender be the ip address of the machine that the server is running on, so instead of locahost 127.101.51 or something

My guess would be that for a local (within a single network) game, you would need to give it a local ip address. so 192.168.xxx.xxx (whatever is assigned by the router).

Every computer in any TCP/IP network … like the Internet, or the network in your home … has an IP-address. The address is, no doubt, a set of 4 numbers (each one in the range 0-255… that is to say, four bytes).

There are a few “special” addresses: - 127.0.0.1 always refers to “this box.” It goes by the name “localhost,” or is sometimes called a “loopback.” - Addresses such as “192.168.xxx.xxx” are called non-routable addresses. That is, they always refer to “this network.” The addresses of the various items within your home-network will be like this. (There are several designated groups of “non-routable addresses” to choose from…)

Your entire house has only one IP-address, though, as far as the Internet-at-large is concerned. That address is held by, and known only to, your “router.” What the router does, then, is to distribute inbound and outbound traffic between “the Internet” and “your home network.” (They are, and they remain, two separate networks. Your router serves as the so-called gateway between them.)

If you want to game within your home, it’s easy: the IP-addresses are unique and they are confined to your home.

If you want to game with your neighbor, however, the traffic will have to go through two routers… yours, and your neighbor’s. The trick is, you won’t see the IP-addresses within your neighbor’s network. Instead, the traffic will come from the (Internet…) IP-address of your neighbor’s router, and a particular port-number, which is rather like a telephone “extension.” (Port-numbers are assigned by the router, and they are actually “how routers know how to distribute the traffic.”)

In a small game, the computers can talk directly to one another … so-called peer-to-peer. But as the number of players increases, it becomes more efficient to route all the traffic to a central server, a so-called socket server, whose job is to maintain the state of the game and to send-and-receive appropriate notification messages from the players. In effect, the socket-server(s) “run” the game, while the individual client-computers manage the drawing of what you see.

There are many commercial socket-servers, but there are open-source ones too. The programming required to implement such a server is both “not trivial” and “highly repetitive,” since it is the necessary-foundation upon which the game-specific logic is based. That’s why you usually see games being constructed around such a foundation, and maintained by vendors who license them for their profit.

Ok all I want to do for now is a simple proof of concept IM.

All I need is to (it doesn’t have to work in blender, just in terminal) to have a live session via: lan connection. All it has to do is this:

user1 = raw_input("User %: ")
user2 = raw_input("User %: ")

print user1
print user2

how would I get it to work right? (from there I’d just loop the script) It’s for me and my brothers evergoing game project Jedi Battles (It’s so we can have a python IM client run during the game [like STEAM])

Just PM me if you have the solution. (btw: it would be nice to print the date [ie: user1 entered the chatroom 1.3.2009 [8:30PM]])

Hey everyone,
(thanks for the info on ip addresses sundialsvc4)

I’ve been doing some more research on this and will be updating the tutorial and including an example of a chat system in blender and some better examples of structuring your game to work with a server.

I’ve done this before, and I might wanna warn you, that “localhost” is well, local. My friend spent a frustrating week trying to get an interent connection to work. instead of “localhost” enter your computer name. That what you need for LAN anyway.

Really cool, well done!

Servers’ anything that connect the internet, you need supercomputers to make a webpage for millions of people. For just two guys playing, you can use a normal computer.

I am no expert but i think there is a difference between a hardware server and a software server. The hardware server is what is bought. A software server is like a background process on your computer that sits there and waits for clients to “serve” I can’t explain it too much as it has been awhile since I’ve read about socket programming.

Any computer can be a server. Those big fancy ones just do the job better. But I’ve got a 2.1ghz Athlon 64 X2 with one gig of ram acting as an SVN, Unreal Tournament, and what ever I feel like messing with server. Granted I don’t run too much at once, like the UT server I usually leave off until I play.

Thanks for the info andrew-101. This will come in handy when I get around to tackling networking in my current project.

Well the software server is just a program to receive information and process commands then re send information.

In the update on the tutorial I will be using TCP sockets and threads.

Tutorial is updated :slight_smile:

Couldn’t you do something like this?


if n == 1:
        lines[0].Text = GameLogic.chat_log[n - 1]
elif n > 6:
        n = 7
else:
        for i in range(0,n):
            lines[i].Text = GameLogic.chat_log[n - (i + 1)]

I’m not sure what these lines that you’ve written would do, but you can very easily replace the tons and tons of if statements with just a for loop from 0 to n. I had the other cases just in case you needed the special cases of n==1 and n > 6.

The ‘lines’ are the lines that chat is displayed in, n is the length of the chat log (n = len(GameLogic.chat_log) ) I should of put that up top, so the code is checking how many lines there are then displaying the last message in line0, 2nd last on line1.

for loop from 0 to n

Thank you! thats what I need.

hi where do i put the server.py script in??
and on your client how do i type the pass in when i start up by the login???

You put the server.py script anywhere you want, just make sure its running when you start the blend.

Choose any user name you want, but just make the pass what the user was, so if I used ‘andrew’ as my user my pass would also be ‘andrew’.

I get

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/tba/public_html/index.php:4) in /home/tba/public_html/libraries/joomla/session/session.php on line 413

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/tba/public_html/index.php:4) in /home/tba/public_html/libraries/joomla/session/session.php on line 413

Warning: Cannot modify header information - headers already sent by (output started at /home/tba/public_html/index.php:4) in /home/tba/public_html/libraries/joomla/session/session.php on line 416
Array ( [0] => option [1] => Tutorials [2] => creating-a-server-for-a-game.html )

when I click the link