Skip to content

Commit

Permalink
site: enrich the doc about using UDP packets
Browse files Browse the repository at this point in the history
Fixes #164
  • Loading branch information
panjf2000 committed Dec 6, 2020
1 parent e72c003 commit 0047c15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion website/blog/2020-03-13-presenting-gnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ events.Tick = func() (delay time.Duration, action Action){

`gnet` supports UDP protocol so the `gnet.Serve` method can bind to UDP addresses.

- All incoming and outgoing packets will not be buffered but read and sent directly.
- All incoming and outgoing packets will not be buffered but read and sent directly, which means all functions of `gnet.Conn` that manipulate the internal buffers are not available; users should use the `frame []byte` from the `gnet.React(frame []byte, c gnet.Conn)` as the UDP packet instead calling functions of `gnet.Conn`, like `c.Read()`, `c.ResetBuffer()`, `c.BufferLength()` and so on, to process data.
- The `EventHandler.OnOpened` and `EventHandler.OnClosed` events are not available for UDP sockets, only the `React` event.
- The UDP equivalents of `AsyncWrite([]byte)` in TCP is `SendTo([]byte)`.

Expand Down
6 changes: 3 additions & 3 deletions website/blog/2020-03-14-presenting-gnet-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,9 @@ events.Tick = func() (delay time.Duration, action Action){

`gnet` 支持 UDP 协议,所以在 `gnet.Serve` 里绑定允许绑定 UDP 地址,`gnet` 的 UDP 支持有如下的特性:

- 网络数据的读入和写出不做缓冲,会一次性读写客户端。
- `EventHandler.OnOpened``EventHandler.OnClosed` 这两个事件在 UDP 下不可用,唯一可用的事件是 `React`
- TCP 里的异步写操作是 `AsyncWrite([]byte)` 方法,而在 UDP 里对应的方法是 `SendTo([]byte)`
- 网络数据的读入和写出不做缓冲,会一次性读写客户端,也就是说 `gnet.Conn` 所有那些操作内部的 buffer 的函数都不可用,比如 `c.Read()`, `c.ResetBuffer()`, `c.BufferLength()` 和其他 buffer 相关的函数;使用者不能调用上述那些函数去操作数据,而应该直接使用 `gnet.React(frame []byte, c gnet.Conn)` 函数入参中的 `frame []byte` 作为 UDP 数据包
- `EventHandler.OnOpened``EventHandler.OnClosed` 这两个事件在 UDP 下不可用,唯一可用的事件是 `React`
- TCP 里的异步写操作是 `AsyncWrite([]byte)` 方法,而在 UDP 里对应的方法是 `SendTo([]byte)`

## Unix Domain Socket 支持

Expand Down

0 comments on commit 0047c15

Please sign in to comment.