IzEmultyScript3 - Multy Client and A Server - Sample!

(IzE_Design) #1

Hi… i have make my last script for the NETWORK multiplayer… this is the 3° version and for the first time include 1 External indipendent SERVER and MULTI Client, in that sample MAX 5 player…

The script of server is in only Python, and i have create the STandAlone using “py2exe” from www.py2exe.org

The client was make with:
-Blender 2.44
-Python 2.5
-Windows XP Pro SP2

I have make and test it on this programs, i dont have idea if this sample work in othere operative system… sorry for that!

Now the sample:
The file include the Source, blend file for client and python for server, and the StandAlone of Windows, with the list of library and module that you must integrate with exe for work it in PC without blender and python…

http://www.izedesign.it/filez/izemultiscript3_sample.rar [7Mb]
—VIDEO (a small demostration that the script work!):

#by IzE_Design - [www.izedesign.it#](http://www.izedesign.it/#) 
#---        THE SERVER        ---# 
from socket import * 
from thread import * 
from struct import * 
SMain = socket(AF_INET, SOCK_STREAM) 
SMain.bind(('', 7000)) 
DataBase = ["","","","",""] 
IpAddr = "" 
Port = 0 
CountClient = 0 
def SClient(TPort, TnumbClient): 
    LocalDB = ["","","",""]  
    Sc = socket(AF_INET,SOCK_DGRAM) 
    Sc.bind(('', TPort)) 
    while 1: 
        CountDB = 0 
        CountLDB = 0 
            CData,Addr = Sc.recvfrom(1024) 
            DataBase[TnumbClient] = str(CData) 
        while CountDB < 4: 
            if CountDB <> TnumbClient: 
                LocalDB[CountLDB] = DataBase[CountDB] 
                CountLDB += 1 
                CountDB += 1 
                CountDB += 1 
        OData = pack('27s27s27s27s',LocalDB[0],LocalDB[1],LocalDB[2],LocalDB[3]) 
        Sc.sendto(OData,(Addr[0],int(TPort + 100))) 
while 1: 
    print "Wait Client Connection..." 
    Conn, IpAddr = SMain.accept() 
    NameClient = Conn.recv(1024) 
    print "... ", CountClient, NameClient, IpAddr[0], "was connect!" 
    Port = 7001 + CountClient 
    TClient = start_new_thread(SClient,(Port, CountClient)) 
    CountClient += 1 
#---         THE END          ---# 

This is the base of Network script, there arent controller for the disconnection and full server… and other…

The script is really simple:
1 internal database that store all information of all player, a first socket (TCP type) that take the client connection and start a new threadh for the client connection with a specific Port for communicated: Port 7000 for the connection communicated, Port 7001 and 7101 for the first client, 7002 and 7102 for the second and continue…
In the thread there are and other socket (UDP type) that receive the data from the client, store it in the database, there are anothere LOCAL database for archivie the Data of othere player without the data of the player, for resend it at player and view the state of othere player…

The client is same: One first socket for connect to server (TCP) and a second socket (UDP with setblocking(0) for not blocking the game) for the communicate…

NOTE: there are a problem with the rotation of othere player, because the function “Mat2euler” and “Degrees” that i have use dont work good… i hope to find the problem soon…

I release that script and sample in GPL licence, you can use where you want without problem, but i am the author :D:D:D

That all! Happy Blending! :yes:


(OTO) #2

looks GREAT!!
Is this working on Linux?


(black reaper) #3

i don’t know how to make net game working but it looks very promising


(chuzzy06) #4

You rock IZE! I started intergrating my game with your network structure but then I switched over to braveheart’s which was made off of bzoo. Now I get to use this again (which personally I find much easier to incorperate). Thanks a million :slight_smile: !


(tedi) #5

Interesting …

maybe you (or somebody) could try to make a (spinoff version ?) that would work over internet, too?

from the top of my head python should have all modules needed … f.e.:


(Farthioner) #6

.blend? :slight_smile:


(Mico27) #7

Wow! that is sweet!!! really thkx for sharing IzE!


(IzE_Design) #8

there are a problem… i have see that the script use 100% of CPU and some Kb/sec for the network for client… this is because the script of multiplayer work every frame, same 60 times in second… is possible reduce it add a controller that send the data every 5 cycle for sample… :wink: i hope that this dont add another lag in trasmission :smiley:


(chuzzy06) #9

Is this possible to work over the internet?


(Olm-Z) #10

Great ! I got it running on Ubuntu without problem with the server.py and .blend files … :slight_smile: (just I didn’t tried with lan nor internet, only on the same computer)
Only there is some dissynchronisation from time to time (the car of player 2 got freezed in the view of player 1 or the contrary … and resynch after few sec) but globaly it works great…

I would just have loved to have the server detecting disconnection. It’s not good to have to relaunch it each time player change… ('cos when you disconnect and reconnect, server say “not permitted”)

good job also with the game setup, nice little cars and scenery ;)… it almost make me think of a great old game that called “big red racing” that was really funny…


(Túrin Turambar) #11

looks great man!!


(chuzzy06) #12

so had anyone gotten it to work over the internet?


(IzE_Design) #13

Yes, work on internet… you can share the IP of the server: http://whatismyip.com/
this is your ip for the internet… i have test it and work… but i dont have idea if you use a router if the ip is the same of all pc in lan or different…

for the disconnection… this version is a base version, i have insert the basilar for work it… later i incoming to insert something to improve the script… for example the disconnection…

my idea is to insert, in server, an other thread with a counter, the counter is reset always the server receive a data… if dont receive a data for some time disconnect it…

but the problem is… if i’m in a thread, i can terminate anothere threadh?, for example the thread that have generate me?

Now i stay working on a new game, a CarGame, the sequel of my CarArena with this my multiplayer and i hope the single player :smiley:


(tedi) #14

couldn’t you use asyncore for that? http://docs.python.org/lib/module-asyncore.html
for what I understand it would be appropriate for internet version as well.
anyhow, might be wrong though.


(chuzzy06) #15

im sorry but could you give an example of handling with the asyncore module?