Esempio n. 1
0
func main() {
	var wg sync.WaitGroup
	wg.Add(3)

	//rand.Seed(time.Now().UTC().UnixNano())
	connection := sip.Start("127.0.0.1:5060")

	// Outbound channel uses connection to send outgoing datagrams
	outbound := make(chan Packet)
	// Inbound channel passes received datagrams to handleIncomingPacket function
	inbound := make(chan Packet)

	// Goroutine for passing incoming datagrams to handleIncomingPacket function
	go recv(connection, inbound, &wg)
	// Goroutine for processing incoming datagrams
	go handleIncomingPacket(inbound, outbound, &wg)
	// Goroutine for sending outgoing datagrams
	go send(connection, outbound, &wg)
	wg.Wait()

}
Esempio n. 2
0
func main() {
	var wg sync.WaitGroup
	wg.Add(3)

	//rand.Seed(time.Now().UTC().UnixNano())
	connection, _ := sip.Start("127.0.0.1:5160")

	// Outbound channel uses connection to send outgoing datagrams
	outbound := make(chan Packet)
	// Inbound channel passes received datagrams to handleIncomingPacket function
	inbound := make(chan Packet)

	// Goroutine for passing incoming datagrams to handleIncomingPacket function
	go recv(connection, inbound, &wg)
	// Goroutine for processing incoming datagrams
	go handleIncomingPacket(inbound, outbound, &wg)
	// Goroutine for sending outgoing datagrams
	go send(connection, outbound, &wg)

	// Prepare peer data
	remotePeerAddr, err := net.ResolveUDPAddr("udp", "localhost:5060")
	if err != nil {
		log.Fatal(err.Error())
		os.Exit(1)
	}

	ticker := time.NewTicker(time.Millisecond * 300)
	go func() {
		for _ = range ticker.C {
			// Prepare INVITE
			newRequest := sip.MakeRequest("INVITE")
			outbound <- Packet{remotePeerAddr, []byte(newRequest)}
		}
	}()
	time.Sleep(time.Second * 1)
	ticker.Stop()
	wg.Wait()

}