0

I have created a game that works with Socket.io and sends info as JSON object to node.js.
Now I decided to replace JSON with the Protobuf protocol.

How should I make a string serialized in Unity and then use socket.emit("anyevent",ProtobufsObject); and send it to node.js socketio listener?

I know how use protobufs in unity just can't figure it out how to send protobuf via socketio.

mihai
  • 37,072
  • 9
  • 60
  • 86
  • You could checkout this https://forum.unity.com/threads/protobuf-net-unity-is-it-worth-it.288007/ on how to define your objects to be serializable via Protobuf. Then, if the protobuf serializer does not return a string, it should return a byte array. Checkout this: https://stackoverflow.com/questions/11654562/how-convert-byte-array-to-string on how to convert the byte array to string in order to send it via the web socket. It could be possible that you can send the byte array directly, but I am not sure if the websocket libraries you use support it. – Angelos Kyriakopoulos Nov 07 '18 at 17:42
  • tnQ. yes currently I do such way like yours ..I will comeback after completing my project and write complete solution for others ,too. – Behrang Taheri Nov 08 '18 at 12:18
  • Awesome, I am moving the comment to the answers. Of course, If you find a better way you can edit it. – Angelos Kyriakopoulos Nov 08 '18 at 13:58

1 Answers1

1

It could be possible that you can send the byte array directly, but I am not sure if the web socket libraries you use support it