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/izemultiscript3_sample.rar [7Mb]
—VIDEO (a small demostration that the script work!):
http://it.youtube.com/watch?v=MBOr59J241Q
—SCREENSHOT:
—SCRIPTs:
#by IzE_Design - [www.izedesign.it#](http://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 :D:D:D
That all! Happy Blending! :yes: