Wsag 2.6x

is there a WSAG ported from 2.49 to 2.6 out there? and if it is, where can i find it?

There may have been. I ported the simple network to 2.5, which is the same as 2.6 for core python.
However, if you’re using WASG you may as well learn how it works, or look in the resources thread; there are plenty examples for multiplayer including my own.
Not to say that WSAG is bad, no, just that it’s a bit of a job to port the full code base.

I dont use it, but I lock in the code it is using to learn from it. I’m prety new to pyton 3 and needed to se if the socket module where handeled in the same way in blender 2.6 (py 3) as in 2.49b (py 2.62) you se I have ben whriting a code for a server that is runing in an separate python console (not in blender at all) and is now about to whrite a client that is listening for this server inside blender. the thing is that when i run my client apart from blender i use a while loop that always lock for commands from the server, when it got comands it keep on going. this don’t work in the blender game engine bco the engine need the script to finich before it goes to the next frame and it won’t do that untill it gets an answere from the server, this makes the engine “freeze”. in the WSAG ths script bind the socket at the first run, and after that let it be bound. code:

if obj.OneTime == 0:
ServerIP = GameLogic.IP
Serverport = 10000
Clientname = ‘’
ClientPort = 10001
GameLogic.sClient = socket(AF_INET,SOCK_DGRAM)
GameLogic.sClient.bind((Clientname,ClientPort))
GameLogic.host = (ServerIP,Serverport)
GameLogic.sClient.setblocking(0)
obj.OneTime = 1

the problem is that when i try to do it in this way in blender 2.6 the socket dosen’t seem to be bound when the script starts over.
and when the script starts over alos the GameLogic.sClient don’t got an value bco the OneTime is now equals to 1, and the script skips the part when the GameLogic.sClient gets a value.

sry 4 bad eng


# Example client
import bge
import socket

def client(cont):
own = cont. owner

if not 'init' in own:
    own['init'] = 1

    ip = ''
    host_port = 10000
    client_port = 10001

    local = ('', client_port)
    host = (ip, host_port)

    own['client']  = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    own['client'].bind(local)
    own['client'].setblocking(0)

    own['connections'] = { 'local' : local, 'host' : host }

    # End of 'init'

host = own['connections']['host']

data = 'test_string'

own['client'].sendto(data, host)


where can i find and have a lock at that? :smiley:

nice and big thx!

the thing whit my client is that it don’t need to send anything (i’ll do that in another script) it only need to recive data from the server but i can’t seem to find out how to do that,… this is the client code i got:


import bge
import socket
import pickle
cont = bge.logic.getCurrentController()
obj = cont.owner
players = ""
text = " "
ov = 2
if obj["activ"] == 0:
    try:
        Clientname = ''
        ClientPort = 3560
        client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        client_socket.bind((Clientname,ClientPort))
        client_socket.setblocking(0)
        print(client_socket)
        obj["activ"] = 1
    except:
        print("socket not bound to 3560")
try:
    data, address = client_socket.recvfrom(256)
    UPData = pickle.loads(data)
    print (UPData)
    players = UPData[0][0]
    text = UPData[0][1]
    ge = str(text, "latin-1")
    print ("the ip :" , ge)
except:
    pass
    print("diden't try")

and this is my server so far (dosen’t run inside of blender):


import socket
import pickle
server_socket = None
try:
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error as msg:
    server_socket = None
try:
    server_socket.bind(("", 5000))
except socket.error as msg:
    server_socket.close()
    server_socket = None
if server_socket is None:
    print('could not open socket')
    sys.exit(1)
L = list()
print("UDPServer Waiting for client on port 5000")
tn = 0
players = 0
while 1:
    data, address = server_socket.recvfrom(256)
    if not data: break
    ge = str(data, "latin-1")
    print ("( " ,address[0], " " , address[1] , " ) said : ", ge)
    if address[0] in L: 
        print("this adress is alredy listed")
        tn = 0
    else:
        L.append(address[0])
        players = players + 1
        tn = 0
        for item in L:
            print (item)
    g = len(L)
    print(g,tn)
    eng = address[0] + " Said: " + ge
    demsg = bytes(eng, "latin-1")
    d1 = (players,demsg)
    dat = pickle.dumps((d1,))
    while tn < g:
        server_socket.sendto(dat, (L[tn],3560))
        print("sent to client: ", tn)
        tn = tn + 1
 

this is the script as I so far use to send data whit ( not inside blender yet, but will be inclueded inside the client) for now it only runs in a separate window:

import socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
valu = 2
valu = int(input(“press 1 and enter to open message menu, press 2 to exit”))
while valu == 1:
msg = input("Message: ")
demsg = bytes(msg, “latin-1”)
client_socket.sendto(demsg, (“127.0.0.1”,5000))
print ("your message: ", msg)
valu = int(input(“1 and enter to send a new message, press 2 to exit”))
client_socket.close()

the reason why i want my script to work in this way is bco the server will be able to take alot of connections, it will be able to spawn a new player that never been connected before at any time.

Running this in module mode will print any received data, or return from the function:


# Example client
import bge
import socket

def client(cont):
    own = cont. owner

    if not 'init' in own:
        own['init'] = 1
    
        ip = ''
        host_port = 1000
        client_port = 1001
    
        local = ('', client_port)
        host = (ip, host_port)
    
        own['client']  = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        own['client'].bind(local)
        own['client'].setblocking(0)
    
        own['connections'] = { 'local' : local, 'host' : host }
    
        # End of 'init'
    
    host = own['connections']['host']
    
    try:
        data, connection = own['client'].recvfrom(1024)
       
    except socket.error:
        return
    
    print(data)

hmm… when i run the server I posted above and this script inside of blender i get this error message when i try to send some data:

Traceback (most recent call last):
File “blenderserver.py”, line 22, in <module>
data, address = server_socket.recvfrom(256)
socket.error: [Errno 10054]
an existing connection was forced to turn off the remote host

what does this error message means and why does it occur? it is the same as when i run my own client script

It should work. Leave it at 1024 instead of 256

tryed it, and it still don’t, gives me the same error :S

if i use this script it do work, but then blender is stuck at the first frame


import socket
import pickle
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client_socket.bind(("", 3560))
v2 = 1
while v2 == 1:
    data, address = client_socket.recvfrom(1024)
    UPData = pickle.loads(data)
    print (UPData)
    players = UPData[0][0]
    text = UPData[0][1]
    ge = str(text, "latin-1")
    print ("the ip :" , ge)

post the blend from before with the code i made.

net test.blend (257 KB)

here are the .blend

So, it works for me.
Number 1, you have to encode your data to bytes; use rencode/zlib with JSON or pickle, (or just JSON or pickle).
Now, you have to tell the send script that the server is your pc - use “localhost” for the server ip when testing.
You’re using the script wrong; it is in module mode, so you set the python controller to “module mode” and type “client.client” using your setup.
Likewise, the server needs to use the encoding and decoding.
Remove the “init” property; i make the code check if there ISNT a property, and if not (assuming a new game), it sets up the client and then adds the “Init” property. If you have one already it won’t init.

thanks man!, I had no ide that there even where a “module mode” and it is now working like a shame :wink:

WSAG5 is under development!! I don’t know if Oldjim announced yet, since he’s very busy, but it should be like at 20% for now! So it’s not ready for use yet!
Good thing that you found a solution!