【问题标题】:Difference between functioning of net.Listen and http.ListenAndServenet.Listen 和 http.ListenAndServe 功能的区别
【发布时间】:2018-08-09 08:06:51
【问题描述】:

我是 Go 和网络的新手。我知道 net.Listen 和 http.ListenAndServe 都创建了一个服务器。但是它们的功能有什么区别呢?

【问题讨论】:

  • 一个(来自包 net)是一个低级别的 tcp/udp 连接,而另一个(来自 net/http)实现一个 HTTP 服务器。第一个是基本的网络连接,而另一个是 HTTP on top 的低级连接的完整实现。
  • 谢谢!但是您所说的低级连接是什么意思?
  • 参见例如en.wikipedia.org/wiki/List_of_network_protocols_(OSI_model) 根据 TCP 是第 4 层,HTTP 是第 7 层。

标签: go server network-programming go-http


【解决方案1】:

基本上,正如documentation 对net.Listen 所说:The network must be "tcp", "tcp4", "tcp6", "unix" or "unixpacket".

http.ListenAndServe 创建 HTTP 服务器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多