File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1+ // A simple echo server implementation from net.Listener official documentation.
12package main
23
34import (
@@ -8,26 +9,35 @@ import (
89)
910
1011func main () {
12+ // Daemonizing echo server application.
1113 switch isDaemon , err := daemon .Daemonize (); {
1214 case ! isDaemon :
1315 return
1416 case err != nil :
15- log .Fatalf ("Error : could not start daemon, reason -> %s" , err .Error ())
17+ log .Fatalf ("main() : could not start daemon, reason -> %s" , err .Error ())
1618 return
1719 }
20+ // From now we are running in daemon process.
1821
22+ // Listen on TCP port 2000 on all interfaces.
1923 l , err := net .Listen ("tcp" , ":2000" )
2024 if err != nil {
2125 log .Fatal (err )
2226 }
2327 defer l .Close ()
2428 for {
29+ // Wait for a connection.
2530 conn , err := l .Accept ()
2631 if err != nil {
2732 log .Fatal (err )
2833 }
34+ // Handle the connection in a new goroutine.
35+ // The loop then returns to accepting, so that
36+ // multiple connections may be served concurrently.
2937 go func (c net.Conn ) {
38+ // Echo all incoming data.
3039 io .Copy (c , c )
40+ // Shut down the connection.
3141 c .Close ()
3242 }(conn )
3343 }
You can’t perform that action at this time.
0 commit comments