我使用 go-diameter 作为客户端尝试连接到服务器。我按照 repo 上的示例进行操作,但发现连接时发生了一些错误。这是我的示例代码:
cfg := &sm.Settings{
OriginHost: datatype.DiameterIdentity(originHost),
OriginRealm: datatype.DiameterIdentity(originRealm),
VendorID: diameterVendorID,
ProductName: productName,
FirmwareRevision: firmwareRevision,
HostIPAddresses: []datatype.Address{
datatype.Address(net.ParseIP(viper.GetString("my.ip"))),
},
}
// Create the state machine (it's a diam.ServeMux) and client.
mux := sm.New(cfg)
// CER -> for sending
cli := &sm.Client{
Dict: dict.Default,
Handler: mux,
MaxRetransmits: 3,
RetransmitInterval: time.Second,
EnableWatchdog: true,
WatchdogInterval: 5 * time.Second,
AuthApplicationID: []*diam.AVP{
// Advertise support for credit control application
diam.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(diameterAuthAppID)), // RFC 4006
},
}
mux.Handle(diam.CCA, handleCCA())
mux.Handle(diam.DPA, handleDPA())
// Print error reports.
go printErrors(ctx, mux.ErrorReports())
println("diameter connect....")
connect := func() (diam.Conn, error) {
/*I test these two ways, both return same error*/
return cli.DialTimeout(addr, 5*time.Second)
//return dial(cli, addr, "", "","tcp", false)
}
c, err := connect()
if err != nil {
println(err)
}
该代码就像 go-diameter repo 上的示例客户端代码一样,但我会收到以下错误:
diameter connect....
diameter error on x.x.x.x:3868: read tcp x.x.x.x:60766-\u003ex.x.x.x:3868: use of closed network connection
欣赏是否有任何建议。谢谢。