import socket # Modulo para comunicacion en red
import pickle # Modulo empacador
import GameLogic as G # El modulo mas sexi
C = G.getCurrentController()
O = C.getOwner()
# Check if server is already conected (see script ServidorCon)
if O.Conectado == 1: # This is a property in the object Main
# Flag for recieved data
rec = 1
# Recieve data from client
try:
recData = G.conn.recvfrom(1024)
data = recData[0]
except:
rec = 0
# If data is recieved
if rec == 1:
if data:
# Unpack Client Data
G.DatosCliente = pickle.loads(data)
# Send data to client, this global list is filled
# from various other scripts to be sent in a single package
# to the cient
data = pickle.dumps(G.DatosServidor)
G.conn.sendto(data, recData[1])
else:
# Close conection
G.conn.close()
# Disconected
O.Conectado = "FALSE"