Listen and serve HTTP on multiple IP addresses

3,868 views
Skip to first unread message

Mauro Romano Trajber

unread,
Aug 28, 2012, 10:53:02 AM8/28/12
to golan...@googlegroups.com
How can I listen and serve HTTP on multiple IP adresses using the Go standard library ?

I have a server with many IP adresses and network interfaces and I want to listen and serve HTTP on two addresses. Using the Serve function of net/http package I can specify only one net.Listener.

Suppose that I want to listen and serve on 10.0.0.1:80 and 10.0.0.2:80 simultaneously. Is it possible ? How ?

ln, err := net.Listen("tcp", "10.0.0.1:80")
...
http.Serve(ln, nil)




DisposaBoy

unread,
Aug 28, 2012, 5:27:01 PM8/28/12
to golan...@googlegroups.com
http://play.golang.org/p/2IrtRqdGit seems to function correctly as expected so I guess you can just listen an N address and call http.Serve on them all

 

Mauro Romano Trajber

unread,
Aug 28, 2012, 5:55:52 PM8/28/12
to DisposaBoy, golan...@googlegroups.com
This is what I was imagine, call Serve in two different goroutines. 
Reply all
Reply to author
Forward
0 new messages