doulanli6146 2014-06-30 06:18
浏览 51
已采纳

去监听已经使用的端口,不返回错误

I already have a webserver which is listening on port 80 (written in node.js). When I run another webserver that also listens on port 80 (written in Go), the Go webserver doesn't raise an error.

How can this occur.

My OS is windows and go version go1.2.2.

  • 写回答

3条回答 默认 最新

  • ds3422222 2014-06-30 07:03
    关注

    I had this happen at work. The golang server will be listening to the IPv6 port 80 while the other application is only listening to IPv4.

    For me the golang app was running first. And it stop listening to v4 and then resumed once the other app was closed.

    [edit later] To demostrate this, I just ran the WinSock bind/listen C++ code found on this MSDN page with the port changed to 80, then I used this Go code:

    package main
    
    import (
        "log"
        "net/http"
    )
    
    func main() {
        http.Handle("/", http.FileServer(http.Dir("c:\\temp")))
        log.Fatal(http.ListenAndServe(":80", nil))
    }
    

    This setup worked because the C++ was listening to 127.0.0.1 and the Go on 0.0.0.0 Changing the go code to log.Fatal(http.ListenAndServe("127.0.0.1:80", nil)) caused the error message nemo suggested.

    I then started my main production code, which has a Mongoose HTTP instance, and it's listening on 0.0.0.0:80, and then ran the above Go code (removing 127.0.0.1) and both are listening to 0.0.0.0:80, this can be seen via Process Explorer.

    both apps listening to 0.0.0.0:80

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题