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 932 times
3
-
7The 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
2
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.
![](../../users/profiles/4145098.webp)
Ullaakut
- 2,812
- 1
- 14
- 27