I'm new to Go and Networking. I know both net.Listen and http.ListenAndServe creates a server. But what is the difference between their functionality?
Asked
Active
Viewed 1,984 times
4
-
8The one (from package net) is a low level tcp/udp connection while the other (from net/http) implements a HTTP server. The first is a basic network connection, while the other is a full fledged implementation of HTTP _on_ _top_ of low level conncection(s). – Volker Aug 09 '18 at 08:16
-
Thanks for this! But what did you mean by _low level connections_? – luffy Aug 09 '18 at 11:43
-
See e.g. https://en.wikipedia.org/wiki/List_of_network_protocols_(OSI_model) according to which TCP is level 4 and HTTP is layer 7. – Volker Aug 09 '18 at 12:28
1 Answers
5
Basically, as the documentation says for net.Listen
: The network must be "tcp", "tcp4", "tcp6", "unix" or "unixpacket".
While http.ListenAndServe
creates an HTTP server.

Ullaakut
- 3,554
- 2
- 19
- 34