所以我有基本的 UDP 服务器, 我实施了一些东西, 比如恢复字节阵列, 确切地说, 它是如何由客户发送的( 如果它被收回了 ) 。 Bassicly, 我有客户端、 服务器和共享的类库, 以及类型, 对象可以从客户端发送到服务器, 反之亦然。 所以现在我想把一些对象序列化, 并发送到服务器/ 客户端 。 但我需要知道是哪类对象被重新恢复了, 以正确消除它。 有两个想法可以解决这个问题 :
- Make a "handshake". Send data about what object will be send after, its length, class name, etc. And after it retrive actual data and deserialize it. I know to do it, but since it s UDP, this "handshake" could be lost and I need to re-ask it, so there is pretty complicated logic and network over-usage, but I know how to implement this.
- And second one is identifing type by some hash value. So client sends data which contains hash value of type and piece of data (I will only send my own type s objects, so no need to implement this for C# and Framework types), and I need to determine type by this hash value and server could deserealize it properly.
那么,有什么想法, 如何执行呢?如果我设法避免反省, 因为反省缓慢( 我不在乎大开关的语句, 如果效果更快的话), 它将会是完美的 。