me again, finally able to get back to my attempt to learn networking & sockets with BGE. all the tutorials (totter333, goran, various others) assume that what you want is a multiplayer game, which requires a server, clients, etc. and that’s exactly what most BGE folks want when they tackle networking. so it makes sense.
but i’m actually trying to build something much simpler. right now, all i want is one computer that can send a message and one computer that can listen for a message and then act on it. so i have been line-by-line through these tutorials and tried to separate the most basic send-and-receive stuff and use just that. but so far i have not gotten it to work.
here’s the code for the computer that sends a message (this isn’t in blender, it just runs in the python shell):
import pickle
import socket
host = "10.0.0.10" # this is the sending computer
port = 4445
client = "10.0.0.11" # this is the receiving computer
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serverSocket.bind((host,port))
serverSocket.setblocking(0)
messageToSend = str(input("Message? "))
# as you'll see in the 'listening' code, right now there's only one 'messageToSend' that will do anything: 'spaceBar'
try:
serverSocket.sendto(pickle.dumps(messageToSend), client)
except:
pass
on the listening end is a blender file with the default cube (with dynamic physics). the cube has an ‘always’ sensor connected to a python controller connected to a motion actuator named ‘mover’. the python script goes like this:
import pickle
import bge
import socket
mainSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mainSocket.setblocking(0)
cont = bge.logic.getCurrentController()
mover = cont.actuators["mover"]
mover.useLocalAngV = True
spin = mover.angV[2]
try:
r, addr = mainSocket.recvfrom(100000)
newMotion = pickle.loads(r)
if newMotion == "spaceBar":
spin = spin + 1
mover.angV = [0.0, 0.0, spin]
cont.activate(mover)
except:
pass
and so i hit ‘p’ on the blender game (the listener) and i run the python ‘sender’ script in the python shell and type ‘spaceBar’ in response to “Message?” and . . . nothing happens. that’s my problem.
yes, i’m quite new to this, but i promise i have diligently worked through the various tutorials to try and understand what each class, function, operation, etc. does. for some reason, i can’t get it work on this super-simplified basis.
any thoughts?