如何写一个http server,同时监听http和https请求?

126 views
Skip to first unread message

Changming Sun

unread,
May 12, 2012, 11:10:50 PM5/12/12
to golang...@googlegroups.com

   s := &http.Server{

                   Addr:           ":8080",

                   Handler:        myServeMux,

                   ReadTimeout:    10 * time.Second,

                   WriteTimeout:   10 * time.Second,

                   MaxHeaderBytes: 1 << 20,

         }

         log.Fatal(s.ListenAndServe())

         s2 := &http.Server{

                   Addr:           ":8443",

                   Handler:        myServeMux,

                   ReadTimeout:    10 * time.Second,

                   WriteTimeout:   10 * time.Second,

                   MaxHeaderBytes: 1 << 20,

         }

         log.Fatal(s2.ListenAndServeTLS("mycert.pem", "mykey.pem"))

 

我想同时在这两个端口监听,那么我需要2个线程吗?

Ruiqi Hong

unread,
May 13, 2012, 8:12:11 AM5/13/12
to golang...@googlegroups.com
2012/5/13 Changming Sun <m...@sunchangming.com>

--
官网: http://golang-china.org/
IRC: irc.freenode.net #golang-china
@golangchina

两个函数用go func() 运行,然后,用channel处理退出状况?
Reply all
Reply to author
Forward
0 new messages