Sending objects through datagram

I have been making a multiplayer game that requires me to send very complex data with a datagram. It would be incredibly useful if I could send variable-length lists and user-defined objects over these datagrams. I tried sending the parameters that were to be passed to the constructor, but it is a pain to know what type each of the parameters will be. Is there any way to send objects with a datagram?

A datagram is just a collection of primitives (ints, strings, floats, etc). You can create a protocol and map the variables yourself. You can also serialize python objects to strings using pickle, json, or yaml modules and reconstruct it on the other side, although there is a security risk here as malagnate code can be executed during the deserialization process. Pyro also might do what you need.

If you describe your use case we might be able to point you to the best fit.

For simple primitive types, you can use Panda’s Datagram classes or Python’s struct module as well.