[英]Sending python objects to node.js via socket.io
Ok so what I'd like to do is have a game written in python and for all the multiplayer to be handled socket.io just because these are two things I'm fairly familiar with and I wanna keep possibilities for a web version or web app for the game open 好的,所以我想做的是用Python编写一个游戏,并让所有多人游戏都可以通过socket.io进行处理,因为这是我相当熟悉的两件事,并且我想保留适用于Web版本或Web的可能性打开游戏的应用程序
So what I'm wondering is, how exactly do I do this and would it be better to embed a javascript parser on the client side or contact node.js from python directly 所以我想知道的是,我该怎么做呢?最好在客户端嵌入javascript解析器,或者直接从python与node.js联系
Assuming your Python objects are simple enough (not instances of classes, say), just send a JSON representation ( json.dumps()
) of them to the socket.io side. 假设您的Python对象足够简单(比如说不是类的实例),只需将它们的JSON表示形式( json.dumps()
)发送到socket.io即可。 I am assuming you can parse JSON on the client side if needed. 我假设您可以根据需要在客户端解析JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.