happyman
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
###### tags: `地圖產生器` # How 地圖產生器 show map creation progress? 2023.06.09 by [happyman](mailto:happyman.eric@gmail.com) 最後更新 2023.06.16 地圖產生器: https://twmap.happyman.idv.tw/ ## History 當 server 出圖的時候,需要讓 web client 知道出圖狀態。最早是用 php 的 system() 將 stdout 導向前端頁面。但是長時間跑的 script 前端可能中斷,為了解決這問題,於 2013年改為 Server push 採用 comet 的 ajax 實作 [Ape](https://github.com/APE-Project/APE_Server) ,將執行的過程 "push" 到 web client。中間又混了10年,終於2023年6月,改為 websocket 實作。 ## Current 1. protocol 自訂的 protocol很簡單,client收到訊息之後解析字串,然後輸出訊息、更新progress bar等,訊息不會影響後端,所以沒有考慮 authentication。 解析訊息參考: https://github.com/happyman/twmap/blob/v3.03_v4.34/twmap_gen/js/twmap.js#L124。 1. 前端 Web: 使用會斷線自動重連的 [reconnect websocket](https://github.com/joewalnes/reconnecting-websocket)。channel 由 mapform page 執行時產生,所以每次都會不一樣。所以其他人要猜到 channel 也不容易。 前端就走 wss, 而且可以透過 [cloudflare](https://developers.cloudflare.com/support/network/using-cloudflare-with-websockets/) cdn. 1. 後端 worker: 因為 websocket 的 tool 已經方便到了極點,所以實作起來一點都不費力。常用 socat,那用 websocat ([**web**socket**socat**](https://github.com/vi/websocat)) 就對了。 由 server 發訊息就這麼簡單。 https://github.com/happyman/twmap/blob/v3.03_v4.34/twmap_gen/lib/STB.inc.php#L622 怕字串被 shell 吃掉,所以 base64 encode 一下。 因為透過 websocket 可以躲在 cdn 後面,但 worker 到 client 要透過外部有點多餘,所以在 cmd_make2.php 加上 shortcut。於呼叫 worker 時候指定如 ws://homevm:9002/twmap_ 參考: https://github.com/happyman/twmap/blob/v3.03_v4.34/twmap_gen/cmd_make2.php#L344 既然每次都是連往同一個 ws,所以利用 websocat 的 reuse socket 功能,先把 redirector 跑起來,之後就只要 nc 即可,更快速。避免程式中斷後,daemon 還留在背景,記得要 register shutdown function 跟 catch ctrl-c 等中斷,把 daemon kill 掉。https://github.com/happyman/twmap/commit/de899ac5c4ffe69dbb9346aa5fd79bed93cf0501 1. Websocket Server: 使用 wsbroad ([**w**eb**s**ocket**broad**cast](https://github.com/vi/wsbroad/)) 連上同一個 url 的為同一個 channel,所以以上都連上相同的 channel, /twmap_[channel], twmap_ 是用來做 prefix,可讓前端(haproxy)做識別,萬一同一個 server ip 要送到不同的 websocket server。目前的 domain 是 ws.happyman.idv.tw 藏在 cloudflare 後面。 ``` # haproxy.cfg frontend tile acl hdr_connection_upgrade hdr(Connection) -i upgrade acl hdr_upgrade_websocket hdr(Upgrade) -i websocket acl is_wsbroad path_beg -i /twmap use_backend ws_wsbroad if hdr_connection_upgrade hdr_upgrade_websocket is_wsbroad { ssl_fc } backend ws_wsbroad mode http timeout tunnel 3600s server wsbroad 127.0.0.1:9002 ``` ## Showcast {%youtube _WyosbwPZVE %} https://youtu.be/_WyosbwPZVE ## 其他出圖方式? 其實可以不需要網頁介面,於自己的pc上出圖。 https://github.com/happyman/docker-twmap-cli https://hub.docker.com/repository/docker/happyman/docker-twmap-cli/general ## Feedback 歡迎留下你寶貴的建議。 https://www.facebook.com/twmapgen/ ### history 2023.6.9 initial 2023.6.16 add reuse socket implementation and cloudflare 說明

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully