TCP not working

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
SphericalCow
Posts: 3
Joined: Sat Jan 30, 2021 4:11 pm

TCP not working

Post by SphericalCow »

I am trying to create a TCP client/server setup with pybullet.

I have tried:
server side --
physicsClientId = p.connect(p.DIRECT) # I have also tried p.SHARED_MEMORY_SERVER
client side (testing on the same machine) --
physicsClientId = p.connect(p.TCP, hostName='localhost', port=6667)

but I get the error message:
b3ConnectPhysicsTCP connection failed.

I have scoured the internet, but I haven't found any examples of a working TCP client/server setup in pybullet. Does anyone know how to fix this?

The purpose for this is to create a multiplayer game. I want the main physics client on the server to perform all of the calculations, while the TCP connections are used to send control inputs and receive state updates. Then, each of the clients can render an image using their local client.

If I can't get TCP to work, then I would like to find an alternative. I have looked into saving/loading the system state so I could manually send the updated state to the clients, load the state, and render an image. Unfortunately, it looks like you can only write to a file (which is quite slow) or to some hidden memory which pybullet doesn't provide access to. Of course, one solution would be to render all of the clients images on the server, but ideally I would like to avoid that because it isn't scalable and sending images over the internet is slow. Does anyone have a solution?
SphericalCow
Posts: 3
Joined: Sat Jan 30, 2021 4:11 pm

Re: TCP not working

Post by SphericalCow »

Not a solution but I found a workaround. You can set up a TCP client/server with:

server:
server_id = p.connect(p.GRAPHICS_SERVER)

client:
client_id = p.connect(p.GRAPHICS_SERVER_TCP)

I think the only difference is that this creates a GUI on the server side. Also, note that there is an error if you try to make a function call with physicsClientId=server_id; it only works with physicsClientId=client_id. I think one workaround for this is if you want to set/get data on the server, just create an extra GRAPHICS_SERVER_TCP connected to it on the same machine.
Post Reply