2011/10/18 sail tsao <sail...@gmail.com>:
> 服务器客户端之间的协议需要经常改动,而且很容易出错,我现在用过的办法有以下几种:
> 1.最原始的办法,纯手工,客户端服务器商量好消息格式,确定好消息ID,各自有各自单独的文件定义。(最容易出错)
> 2.制作协议生成工具。协议用XML定义,然后用语法分析库(boost.Spirit)解析XML生成客户端服务器相应的消息定义文件。(现在使用的
> 办法,现对于第一种方便了很多)
>
> 想请问下各位同行还有没有其他更好的办法。
--
Milo Yip
Twitter @miloyip
http://www.cnblogs.com/miloyip/
http://miloyip.seezone.net/
On 10月18日, 下午12时38分, Milo Yip <milo...@gmail.com> wrote:
> 這個最好能滿足DRY principle。
> 用定義文件編譯成目標平台的源代碼是最常見的方法。有時需要跨平台、跨語言。
> 或可參考 google的protobuf的做法 (本人沒研究過)http://code.google.com/intl/zh-CN/apis/protocolbuffers/docs/overview....
>
> 2011/10/18 sail tsao <sail.t...@gmail.com>:
On 10月18日, 下午2时47分, sail tsao <sail.t...@gmail.com> wrote:
> To
> Milo:protobuf之前看过,可惜我们客户端Unity用的是c#,protobuf没法用,确实,现在最好的办法也就是通过xml定义生成跨平台的文 件了。
> To Alex:“各自有各自单独的文件定义”的意思是指客户端服务器是不同语言的时候就没法用一个文件定义消息了
>
Jason, XML, pro buf, Corba, or just original bit stream.
It depends on the requirements,
I had exp of building a dis sys using just bit stream(struct or
class), with around 50 to 100 servers,
but better make sure the servers are based on the same system.(for
small sized system, this is not difficult)
Pro buf is good but time consuming to use it for small and medium
sized projects in my mind.
better write a small RPC api first, based on bit stream is just trick
when handle big little Endian.
On Oct 18, 12:38 pm, Milo Yip <milo...@gmail.com> wrote:
> 這個最好能滿足DRY principle。
> 用定義文件編譯成目標平台的源代碼是最常見的方法。有時需要跨平台、跨語言。
> 或可參考 google的protobuf的做法 (本人沒研究過)http://code.google.com/intl/zh-CN/apis/protocolbuffers/docs/overview....
>
> 2011/10/18 sail tsao <sail.t...@gmail.com>:
>
2011/10/20 William.Wang <egm...@gmail.com>:
> 我们这边直接用结构体定义消息,发送的就是结构体占用的内存.如果版本不一致,就惨了...
(1) In C/C++, it is often needed to store data as pointers in field,
for example, null-terminated string.
(2) Fixed-size array which are not fully populated data will waste
bandwidth, e.g. struct Inventory { Item items[100]; size_t itemCount;
};
2011/10/20 Zhangming Niu <niuzha...@gmail.com>:
On Oct 20, 4:46 pm, Milo Yip <milo...@gmail.com> wrote:
> I just stated some obvious limitations of the method.
>
> (1) In C/C++, it is often needed to store data as pointers in field,
> for example, null-terminated string.
>
> (2) Fixed-size array which are not fully populated data will waste
> bandwidth, e.g. struct Inventory { Item items[100]; size_t itemCount;
>
> };
>
> 2011/10/20 Zhangming Niu <niuzhangm...@gmail.com>:
>
>
>
>
>
>
>
>
>
> > To: milo
>
> > 1 and 3 are not matters
> > pointer的field不能正確傳遞
> > (1)normally no one would pass a pointer, but this can be done although it is
> > tricky .
> > 如果struct裡有固定數組,而實際不是滿的,
> > (2)I do not really understand,
> > maybe you mean 2 power x architecture in the computer, but it wont affect
> > performance
> > because TCP or TCP will tell the length of the byte stream. if 9bytes is
> > sent, then 9 bytes will be received.
>
> > 2011/10/20 Milo Yip <milo...@gmail.com>
>
> >> 這樣做還會有幾個問題:
> >> 1. pointer的field不能正確傳遞
> >> 2. 機器的architecture或compiler不同,內存佈局會不同(32/64-bit, endianess, member
> >> alignment)
> >> 3. 如果struct裡有固定數組,而實際不是滿的,會浪費bandwidth
>
> >> 2011/10/20 William.Wang <egmk...@gmail.com>:
On Oct 20, 4:09 pm, Milo Yip <milo...@gmail.com> wrote:
> 這樣做還會有幾個問題:
> 1. pointer的field不能正確傳遞
> 2. 機器的architecture或compiler不同,內存佈局會不同(32/64-bit, endianess, member alignment)
> 3. 如果struct裡有固定數組,而實際不是滿的,會浪費bandwidth
>
> 2011/10/20 William.Wang <egmk...@gmail.com>:
On Oct 21, 3:29 pm, Zhangming Niu <niuzhangm...@gmail.com> wrote:
> egmkang,
>
> pointers could show up in the struct. just tricky to implement.
>
> 2011/10/21 sail tsao <sail.t...@gmail.com>
>
>
>
>
>
>
>
>
>
> > 压缩并不能解决固定数组没用满的问题。如果固定数组的大小是1000,而协议中只用了其中的1个不是很浪费么?最好就是不用固定数组
> > to egmkang:我们也是在序列化时将字符串转为2字节的长度信息和字符数组放入二进制流,动态数组也是如此处理。
>