HTTP服务无法正常运行

作者:佚名

时间:2024-03-27 08:48

来源:stackoverflow

浏览:265

我正在尝试使用hprose在go中实现rpc服务器。它工作正常,但在添加更多功能后却没有:/有趣的是,它甚至在其他http库(例如fasthttp)上也不起作用。listenandserve()方法似乎在执行过程中卡在某个地方,因为它永远不会返回。可能是什么原因造成的?packagemainimport("net/http""fmt""github.com/hprose/hprose-golang/rpc"log"logu

在 Go 中使用 hprose 实现 RPC 服务器时出现故障,即使切换到其他 HTTP 库(如 fasthttp)也无法正常运行。listenAndServe() 方法在执行过程中卡住,无法返回。程序员怀疑这是导致故障的原因,但尚未确认服务器是否未按预期运行。

问题内容

我正在尝试使用 hprose 在 go 中实现 rpc 服务器。它工作正常,但在添加更多功能后却没有:/

有趣的是,它甚至在其他 http 库(例如 fasthttp)上也不起作用。 listenandserve() 方法似乎在执行过程中卡在某个地方,因为它永远不会返回。可能是什么原因造成的?

package main


import (
    "net/http"
    "fmt"
     "github.com/hprose/hprose-golang/rpc"
    log "logutil"
)

func main() {
    log.InitializeLogger()
    InitializeEthClient()
    InitializeClients()
    server := rpc.NewHTTPService()

    // TxtStorage functions
    server.AddFunction("DeployTxtStorage", DeployNewTxtStorage)
    server.AddFunction("GetPackedData", GetPackedData)
    server.AddFunction("GetReputation", GetReputation)
    server.AddFunction("GetEventsForReputation", GetEventsForReputation)
    server.AddFunction("GetEventsForData", GetEventsForData)

    // Clients functions
    server.AddFunction("RegisterClient", RegisterClient)

    log.Info("Registered server functions!")
    err := http.ListenAndServe(":8080", server)
    fmt.Println(err)
    log.Info("Waiting for incoming connections...")
    log.WriteAway()
}


解决方案


listenandserve 是阻塞的,除非遇到错误,否则它不会返回。您似乎期望打印出最后几行

Waiting for incoming connections...

但是当服务器正在运行时,这种情况永远不会发生。您确定它没有按预期工作吗?

到这里,我们也就讲完了《HTTP服务无法正常运行》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

本文内容来源于互联网,如有侵权请联系删除。

相关文章

更多

热门专题

更多
返回顶部