Results 1 to 15 of 15
  1. #1
    Member IzE_Design's Avatar
    Join Date
    Jul 2006
    Location
    Italy (Cesena)
    Posts
    37

    IzEmultyScript3 - Multy Client and A Server - Sample!

    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...

    ---DOWNLOAD:
    http://www.izedesign.it/filez/izemul...pt3_sample.rar [7Mb]
    ---VIDEO (a small demostration that the script work!):
    http://it.youtube.com/watch?v=MBOr59J241Q
    ---SCREENSHOT:



    ---SCRIPTs:
    Code:
    #by IzE_Design - www.izedesign.it# 
    #--------------------------------# 
    #---        THE SERVER        ---# 
    #--------------------------------# 
     
    #---------------------------Import 
    from socket import * 
    from thread import * 
    from struct import * 
    #-----------------------Initialize 
    SMain = socket(AF_INET, SOCK_STREAM) 
    SMain.bind(('', 7000)) 
    SMain.listen(1) 
    DataBase = ["","","","",""] 
    IpAddr = "" 
    Port = 0 
    CountClient = 0 
    #--------------------------Threads 
    def SClient(TPort, TnumbClient): 
        LocalDB = ["","","",""]  
        Sc = socket(AF_INET,SOCK_DGRAM) 
        Sc.bind(('', TPort)) 
        while 1: 
            CountDB = 0 
            CountLDB = 0 
            try: 
                CData,Addr = Sc.recvfrom(1024) 
                DataBase[TnumbClient] = str(CData) 
            except: 
                pass 
            while CountDB < 4: 
                if CountDB <> TnumbClient: 
                    LocalDB[CountLDB] = DataBase[CountDB] 
                    CountLDB += 1 
                    CountDB += 1 
                else: 
                    CountDB += 1 
            OData = pack('27s27s27s27s',LocalDB[0],LocalDB[1],LocalDB[2],LocalDB[3]) 
            Sc.sendto(OData,(Addr[0],int(TPort + 100))) 
    #--------------------Connect_Cycle 
    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)) 
        Conn.send(str(Port)) 
        CountClient += 1 
        Conn.close() 
    #------------------------------END 
     
    #--------------------------------# 
    #---         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

    That all! Happy Blending!
    POWER OF BLENDER!
    www.izedesign.it




  2. #2
    Hello
    looks GREAT!!
    Is this working on Linux?
    Bye



  3. #3
    i don't know how to make net game working but it looks very promising



  4. #4
    Member chuzzy06's Avatar
    Join Date
    Feb 2006
    Location
    Massachusetts
    Posts
    356
    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 !



  5. #5
    Member
    Join Date
    Jul 2002
    Posts
    1,560
    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.:
    http://docs.python.org/lib/module-SimpleHTTPServer.html
    http://docs.python.org/lib/module-urllib2.html



  6. #6
    .blend?



  7. #7
    Member Mico27's Avatar
    Join Date
    Jul 2007
    Location
    Canada, Quebec
    Posts
    605
    Wow! that is sweet!!! really thkx for sharing IzE!



  8. #8
    Member IzE_Design's Avatar
    Join Date
    Jul 2006
    Location
    Italy (Cesena)
    Posts
    37
    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... i hope that this dont add another lag in trasmission
    POWER OF BLENDER!
    www.izedesign.it




  9. #9
    Member chuzzy06's Avatar
    Join Date
    Feb 2006
    Location
    Massachusetts
    Posts
    356
    Is this possible to work over the internet?



  10. #10
    Member Olm-Z's Avatar
    Join Date
    Apr 2006
    Location
    Bxl - Be
    Posts
    322
    Great ! I got it running on Ubuntu without problem with the server.py and .blend files ... (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....



  11. #11
    looks great man!!
    I most humbly believe that 3DGURU, kbot, lilgrudgeboy, and I hold the BA record for the quickest thread-16 pages in 60 minutes on 12/19/07.



  12. #12
    Member chuzzy06's Avatar
    Join Date
    Feb 2006
    Location
    Massachusetts
    Posts
    356
    so had anyone gotten it to work over the internet?



  13. #13
    Member IzE_Design's Avatar
    Join Date
    Jul 2006
    Location
    Italy (Cesena)
    Posts
    37
    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
    POWER OF BLENDER!
    www.izedesign.it




  14. #14
    Member
    Join Date
    Jul 2002
    Posts
    1,560
    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.



  15. #15
    Member chuzzy06's Avatar
    Join Date
    Feb 2006
    Location
    Massachusetts
    Posts
    356
    im sorry but could you give an example of handling with the asyncore module?



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •