Skip to content

Commit

Permalink
udp readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zuiwuchang committed Sep 12, 2024
1 parent eea71da commit ac28eed
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 1 deletion.
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ index:
* [pipe](#pipe)
* [portal-bridge](#portal-bridge)
* [http-portal-bridge](#http-portal-bridge)
* [udp-over-tcp](#udp-over-tcp)
* [logger](#logger)
* [pool](#pool)
* [api](#api)
Expand Down Expand Up @@ -531,6 +532,78 @@ local portal = {
curl http://127.0.0.1:4000 http://127.0.0.1:4001 http://127.0.0.1:4002
```

# udp-over-tcp

Starting from v0.0.4, basic listener/dialer supports udp. This function is used to implement udp over tcp. This is useful at certain times, for example, a firewall blocks UDP, or UDP is speed-limited. In this case, you can use this function to transmit UDP data using TCP, but note that this will reduce the transmission efficiency of the original UDP program.

```
// Here's a demonstration of how to set up udp over tcp
// This is the configuration on the server, which parses udp from tcp and transmits it to the destination service
local server = {
dialer: [
{
tag: 'google-dns',
timeout: '200ms',
url: 'basic://8.8.8.8:53',
network: 'udp',
udp: {
frame: 16,
timeout: '60s',
size: 1500,
},
},
],
listener: [
{
network: 'pipe',
addr: 'streamf/pipe.socket',
dialer: {
tag: 'google-dns',
close: '1s',
},
},
],
};
// This is a reverse proxy. It receives udp, packages it, and transmits it to the server using tcp.
local proxy = {
dialer: [
{
tag: 'udp-over-tcp',
timeout: '200ms',
url: 'basic://',
network: 'pipe',
addr: 'streamf/pipe.socket',
},
],
listener: [
{
network: 'udp',
addr: ':4000',
dialer: {
tag: 'udp-over-tcp',
close: '1s',
},
udp: {
frame: 16,
timeout: '60s',
size: 1500,
},
},
],
};
{
dialer: server.dialer + proxy.dialer,
listener: server.listener + proxy.listener,
logger: {
source: true,
},
}
```

# logger

logger is used to set logs
Expand Down
72 changes: 72 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ index:
* [pipe](#pipe)
* [portal-bridge](#portal-bridge)
* [http-portal-bridge](#http-portal-bridge)
* [udp-over-tcp](#udp-over-tcp)
* [logger](#logger)
* [pool](#pool)
* [api](#api)
Expand Down Expand Up @@ -532,6 +533,77 @@ local portal = {
curl http://127.0.0.1:4000 http://127.0.0.1:4001 http://127.0.0.1:4002
```

# udp-over-tcp

從 v0.0.4 開始 basic 的 listener/dialer 支持 udp,這個功能用於實現 udp over tcp。這在某些時候是有用的,例如防火牆阻擋了 udp,或者 udp 被限制了速度,這時可以使用此功能來用 tcp 傳輸 udp 數據,但是注意這會降低原本 udp 程序的傳輸效率

```
// 這裏演示了如何實現 udp over tcp
// 這是伺服器上的配置,從tcp解析出udp,傳輸到目的服務
local server = {
dialer: [
{
tag: 'google-dns',
timeout: '200ms',
url: 'basic://8.8.8.8:53',
network: 'udp',
udp: {
frame: 16,
timeout: '60s',
size: 1500,
},
},
],
listener: [
{
network: 'pipe',
addr: 'streamf/pipe.socket',
dialer: {
tag: 'google-dns',
close: '1s',
},
},
],
};
// 這是一個反向代理。它接收udp,將其打包,並使用tcp傳輸到伺服器。
local proxy = {
dialer: [
{
tag: 'udp-over-tcp',
timeout: '200ms',
url: 'basic://',
network: 'pipe',
addr: 'streamf/pipe.socket',
},
],
listener: [
{
network: 'udp',
addr: ':4000',
dialer: {
tag: 'udp-over-tcp',
close: '1s',
},
udp: {
frame: 16,
timeout: '60s',
size: 1500,
},
},
],
};
{
dialer: server.dialer + proxy.dialer,
listener: server.listener + proxy.listener,
logger: {
source: true,
},
}
```

# logger

logger 用於設定日誌
Expand Down
11 changes: 10 additions & 1 deletion bin/example/udp.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ local server = {
{
tag: 'google-dns',
timeout: '200ms',
// url: 'basic://127.0.0.1:9001',
url: 'basic://8.8.8.8:53',
network: 'udp',
udp: {
frame: 16,
timeout: '60s',
size: 1500,
},
},
],
listener: [
Expand Down Expand Up @@ -42,6 +46,11 @@ local proxy = {
tag: 'udp-over-tcp',
close: '1s',
},
udp: {
frame: 16,
timeout: '60s',
size: 1500,
},
},
],
};
Expand Down

0 comments on commit ac28eed

Please sign in to comment.