func xmpp(wg *sync.WaitGroup) { s := &units.Server{Name: server} c := &units.Client{Name: user, Server: s} var redial func(error) dial := func(st stream.Stream) { log.Println("dialing ", s) if err := stream.Dial(st); err == nil { log.Println("dialed") neg := &steps.Negotiation{} actors.With().Do(actors.C(steps.Starter), redial).Do(actors.C(neg.Act()), redial).Run(st) if neg.HasMechanism("PLAIN") { auth := &steps.PlainAuth{Client: c, Pwd: pwd} neg := &steps.Negotiation{} bind := &steps.Bind{Rsrc: resource + strconv.Itoa(rand.New(rand.NewSource(time.Now().UnixNano())).Intn(500))} actors.With().Do(actors.C(auth.Act()), redial).Do(actors.C(steps.Starter)).Do(actors.C(neg.Act())).Do(actors.C(bind.Act())).Do(actors.C(steps.Session)).Do(actors.C(steps.InitialPresence)).Run(st) actors.With().Do(actors.C(bot)).Run(st) } wg.Done() } } redial = func(err error) { if err != nil { log.Println(err) } <-time.After(time.Second) dial(stream.New(s, redial)) } redial(nil) }
func main() { flag.Parse() s := &units.Server{Name: server} c := &units.Client{Name: user, Server: s} wg := new(sync.WaitGroup) wg.Add(1) go func() { var redial func(error) dial := func(st stream.Stream) { log.Println("dialing ", s) if err := stream.Dial(st); err == nil { log.Println("dialed") neg := &steps.Negotiation{} actors.With().Do(actors.C(steps.Starter), redial).Do(actors.C(neg.Act()), redial).Run(st) if neg.HasMechanism("PLAIN") { auth := &steps.PlainAuth{Client: c, Pwd: pwd} neg := &steps.Negotiation{} bind := &steps.Bind{Rsrc: resource + strconv.Itoa(rand.New(rand.NewSource(time.Now().UnixNano())).Intn(500))} actors.With().Do(actors.C(auth.Act()), redial).Do(actors.C(steps.Starter)).Do(actors.C(neg.Act())).Do(actors.C(bind.Act())).Do(actors.C(steps.Session)).Run(st) actors.With().Do(actors.C(steps.InitialPresence)).Run(st) actors.With().Do(actors.C(bot)).Run(st) } wg.Done() } } redial = func(err error) { log.Println(err) <-time.After(time.Second) dial(stream.New(s, redial)) } redial(nil) }() go neo_server(wg) go func() { time.Sleep(time.Duration(time.Millisecond * 200)) //open.Start("http://localhost:3000") //open.Start("http://localhost:3000/stat") }() wg.Wait() }