To answer my own question, I did some tests suggested by a deleted answer.
(1) If I disable Wake for Wi-Fi network access
and put macos to sleep mode, the wifi will be off. (I can not ping the wifi's ip anymore in another client.)
(2) If I enable Wake for Wi-Fi network access
and put macos to sleep mode, the wifi will remain on. (I can ping the wifi's ip successfully in another client.) But even if the wifi is on, my apps will still be disconnected.
Thus, the answer in link: Why does my WiFi disconnect when my Mac goes to sleep:
After a certain time frame, more processes are frozen for the system to save energy.
Disable “Wake for network access” and you shouldn’t have this problem anymore.
The first sentence should be correct. The reason why my apps are disconnected even if the wifi is on is because my apps are frozen when the system is in sleep mode.
But the second sentence is incorrect. Disable the option doesn't solve that problem at all and even make wifi become off in sleep mode.
How to avoid apps disconnecting from network?
Avoid macos switching to sleep mode.
How to stop macos switching to sleep mode on power adapter when locking the screen or display is off?
System Preferences --> Energy Saver --> Power Adapter -->
- Enable
Prevent computer from sleeping automatically when the display is off
- Disable
Put hard disks to sleep when possible
.
How to stop macos switching to sleep mode on battery when locking the screen or display is off?
System Preferences --> Energy Saver --> Power Adapter --> Disable Put hard disks to sleep when possible
.
and then execute the following to disable sleep mode:
sudo pmset -b sleep 0; sudo pmset -b disablesleep 1
This command is untested yet by me and referenced from link