douxun2018 2016-04-09 05:45
浏览 144
已采纳

去套接字服务器出现EOF错误?

My codes:

    var connMax int = 0

    func CheckErr(err error) {
        if err != nil {
            fmt.Fprintf(os.Stderr, "Error occured: %s
", err)
            os.Exit(1)
        }
    }

    func handler(conn net.Conn) {
        defer conn.Close()

        var buf [512]byte
        n, err := conn.Read(buf[0:])
        CheckErr(err)

        connMax += 1
        fmt.Println(connMax)

        result := bytes.NewBuffer(nil)
        result.Write(buf[0:n])

        fmt.Println(string(result.Bytes()))

        conn.Write([]byte("HTTP/1.1 201 OK
"))

    func Run() {
        ln, err := net.Listen("tcp", ":8080")
        CheckErr(err)
        for {
            conn, err := ln.Accept()
            CheckErr(err)
            go handler(conn)
        }
    }

I tried to testing server with command ab of package apache2-utils. ab -c 1500 -n 10000 http://127.0.0.1:8080/

once that finished, EOF error occured, so process exit: enter image description here

  • 写回答

1条回答 默认 最新

  • doujiabing1228 2016-04-09 06:42
    关注

    io.EOF indicates that the connection is closed by the other end. I guess it's because ab reaches the limitation of open file descriptors, so the connection is closed. Use ulimit -a to check it. If it's less than 10000, use ulimit -n 65536 to change it. This is to allow more than 10000 connections. I choose 65536 randomly, and you need root privilege to do this configure.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭