Blender Game Networking using TCP/IP

Hello again guys!,
Need your help once more, if you don’t mind. What I need is a blender program to use TCP/IP to recieve packets. I have a server and client TCP network working properly. Just when I try to get the stuff working in blender, it freezes. So i guesses that i need to use the s.setblocking(). The only thing is that when I use the blocking, the TCP stuff won’t connect. So now im really stumped and don’t have a clue. Would appreciate any help you could give me guys.
Thanks in advance,
Adam

Well, while you run a socket.recvfrom, the process will freeze until data is received! Unless you set a timeout exception, then your script will continue after the timeout. The best solution (at least the one I use), is to use threading, so the socket runs on a separate thread, and you can run the rest on another thread.
Depending on how you design your program, you have to decide what runs when and how!

Thanks for the fast reply!
I think I should fill you in a little about where I’m at :slight_smile:
Basically I have a blender game made so that I can change expressions on a face by using the numbers on my keyboard. Got this to run fine. For the next phase of my project, I need to control this face from another computer over a network. Firstly I tried UDP and I got so far and the thought occured to me that the resources required using TCP would be much less, as the minimization of the resources usage is a must for me. From here, I don’t really have much experience in the field. I’m not really sure which progression I need to connect the IP addresses and to receive. I have no real direction, maybe someone has done something similar before, I think I need to step back and get more basic ideas straight in my head before I get deeper into it. What way would you guys go about this?
Thanks again from the continued help guys,
Adam

I tried writing a game with non-blocking sockets and it started to drop messages when too much was going on. I’d definitely agree with torakunsama’s suggestion of using a different thread for network communication.

Thanks for all the suggestions. Using networking in blender is really starting to annoy me! It works just fine in IDLE but I don’t have a clue how to implement it into blender grrrr

In games, you generally avoid TCP, save for CHAT and certain game modes

The only place I’ve heard TCP used is World of Warcraft. Oh yeah, one more thing about UDP is that the kernel doesn’t always send the data in the order you send them (kind of like a FILO queue). I think in general, packet loss over the internet is not so bad that compensating by resending packets etc. does not make UDP slower than TCP (most of the time anyways).

Networking basics:
http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html
http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/ (see links also)
https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

And for when you start doing lag compensation/entity interpolation/input prediction :p:
https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization

I’m not sure if anyone else suggested this. but yes you do s.setblocking(0) and then instead of just doing the normal s.recv() or s.accept(), you will use select to see if there is anything to recv or if a socket is available to send stuff to and then you do s.recv() etc…

I have done a few games/chat systems using python socket and blender game engine if you’d like to see them.