Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register example - Request Timeout #84

Open
chumvan opened this issue Aug 5, 2022 · 2 comments
Open

register example - Request Timeout #84

chumvan opened this issue Aug 5, 2022 · 2 comments

Comments

@chumvan
Copy link
Contributor

chumvan commented Aug 5, 2022

Hi,
I am trying to implement a simple Registra to store IP of the two SIP device, starting with the examples/register. However, the program failed to make SIP REGISTER and kept showing Request Timeout error as can be seen from the screenshot below:

Screen Shot 2022-08-05 at 9 19 21

Initially I ran the code in the mac M1 and then tried it again with the ubuntu 20.04 virtual machine. Neither of them worked.
I haven't edited the code yet, just cloning and running via go run ./exmples/register/main -c.

package main

import (
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/cloudwebrtc/go-sip-ua/pkg/account"
	"github.com/cloudwebrtc/go-sip-ua/pkg/media/rtp"
	"github.com/cloudwebrtc/go-sip-ua/pkg/stack"
	"github.com/cloudwebrtc/go-sip-ua/pkg/ua"
	"github.com/cloudwebrtc/go-sip-ua/pkg/utils"
	"github.com/ghettovoice/gosip/log"
	"github.com/ghettovoice/gosip/sip/parser"
)

var (
	logger log.Logger
	udp    *rtp.RtpUDPStream
)

func init() {
	logger = utils.NewLogrusLogger(log.DebugLevel, "Register", nil)
}

func main() {

	stop := make(chan os.Signal, 1)
	signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT)
	stack := stack.NewSipStack(&stack.SipStackConfig{
		UserAgent:  "Go Sip Client/example-register",
		Extensions: []string{"replaces", "outbound"},
		Dns:        "8.8.8.8"})

	if err := stack.Listen("udp", "0.0.0.0:5066"); err != nil {
		logger.Panic(err)
	}

	ua := ua.NewUserAgent(&ua.UserAgentConfig{
		SipStack: stack,
	})

	ua.RegisterStateHandler = func(state account.RegisterState) {
		logger.Infof("RegisterStateHandler: user => %s, state => %v, expires => %v, reason => %v", state.Account.AuthInfo.AuthUser, state.StatusCode, state.Expiration, state.Reason)
	}

	uri, err := parser.ParseUri("sip:100@127.0.0.1") // this acts as an identifier, not connection info
	if err != nil {
		logger.Error(err)
	}

	profile := account.NewProfile(uri.Clone(), "goSIP",
		&account.AuthInfo{
			AuthUser: "100",
			Password: "100",
			Realm:    "b2bua",
		},
		1800,
		stack,
	)

	recipient, err := parser.ParseSipUri("sip:100@127.0.0.1;transport=udp") // this is the remote address
	if err != nil {
		logger.Error(err)
	}

	register, err := ua.SendRegister(profile, recipient, profile.Expires, nil)
	if err != nil {
		logger.Error(err)
	}

	time.Sleep(time.Second * 5)

	register.SendRegister(0)

	time.Sleep(time.Second * 5)

	register.SendRegister(300)

	time.Sleep(time.Second * 5)

	register.SendRegister(0)

	<-stop

	ua.Shutdown()
}

I saw some issues mentioned by @brnt but this seems to be a different one. Let me know if I could provide more info
Thank you for your help.

@cloudwebrtc
Copy link
Owner

did you start any sip server?
For example go run examples/b2bua/main.go

@chumvan
Copy link
Contributor Author

chumvan commented Aug 5, 2022

Hi,
Yes, I tried that and was able to see the registration. Thank you!
Just to be sure, Is the port 5066 in this example assigned for the SIP client trying to register itself to the registra inside b2bua and how the function ua.SendRegister() is aware of address 0.0.0.0:5060 of the b2bua shown in my log ? I failed to track that.
Does this register demonstrate a separated example from the client/b2bua mentioned in the README.md i.e. Should the client work if I only run it and the examples/b2bua/main.go ? I will make a new issue if I should describe more details then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants