func main() { dcams.ManifestFileName = "fakeClient.manifest" fakeClient, err := dcams.Open() if err != nil { //What do we need: 1 pull REQ, err := dcams.NewREQ("springInput") dieOnErr(err) fakeClient.Add(REQ) fakeClient.WriteFile() log.Printf("fakeClient REQ key: [\"%s\"]", REQ.PublicKey) log.Fatal("Manually swap keys with remote client trusted list!") } log.Println("Connect") err = fakeClient.Connect() dieOnErr(err) m := Location{Id: "blah", Neighbors: []string{}, Frq: 1.618} mmsg, _ := json.Marshal(m) log.Println(string(mmsg)) err = fakeClient.Resource("springInput").Write(string(mmsg)) dieOnErr(err) asd, err := fakeClient.Resource("springInput").Read() dieOnErr(err) log.Println("ClientFinal", asd) }
func main() { dcams.ManifestFileName = "testserver.manifest" testserver, _ := dcams.Open() log.Println(testserver) log.Println("Connect") testserver.Connect() var c Map dieOnErr(c.readData("http://localhost:9000/public/rsrc/locations.json")) log.Println("Fake data forever") for i := 0; ; i++ { select { case _ = <-time.After(time.Millisecond * 5000): msg := c.nextEvent() mmsg, _ := json.Marshal(msg) //log.Println(string(mmsg)) err := testserver.Local[0].Write(string(mmsg)) dieOnErr(err) } } }
func main() { dcams.ManifestFileName = "springdata.manifest" testserver, err := dcams.Open() if err != nil { //What do we need: 1 pub, 1 REP pub, err := dcams.NewPub("springData") dieOnErr(err) testserver.Add(pub) REP, err := dcams.NewREP("springInput") dieOnErr(err) testserver.Add(REP) testserver.WriteFile() log.Printf("springdata publish key: [\"%s\"]", pub.PublicKey) log.Printf("springInput REP key: [\"%s\"]", REP.PublicKey) log.Fatal("Manually swap keys with remote client trusted list!") } //log.Println(testserver) log.Println("Connect") //subscribe to model go modelDataSub() //Connect to upstream visualization server testserver.Connect() // Connect to model for shuttling upstream requests shuttleRequests, _ := zmq.NewSocket(zmq.PUSH) shuttleRequests.Bind("tcp://127.0.0.1:5560") // async recv upstream visualization requests go upstreamRequests(testserver) log.Println("Shuttle Model Data forever") for i := 0; ; i++ { select { case d := <-modelData: // mmsg, _ := json.Marshal(d) //log.Println("shuttling", string(mmsg)) //log.Println("shuttling", d[0]) err := testserver.Resource("springData").Write(string(mmsg)) dieOnErr(err) case modelUpdate := <-changerequests: //shuttle updates to the model log.Println("Got request", modelUpdate) mmsg, err := json.Marshal(modelUpdate) dieOnErr(err) //log.Println("shuttling", string(mmsg)) _, err = shuttleRequests.Send(string(mmsg), 0) dieOnErr(err) } } }
func main() { dcams.ManifestFileName = "testserver.manifest" testserver, err := dcams.Open() if err != nil { //What do we need: 1 push push, err := dcams.NewPush("testserverData") dieOnErr(err) testserver.Add(push) testserver.WriteFile() log.Fatal("testserver not ready, add key to trusted list ", push.PublicKey) } dcams.ManifestFileName = "web.manifest" web, err := dcams.Open() if err != nil { //What do we need: 1 pull pull, err := dcams.NewPull("testserverData") dieOnErr(err) web.Add(pull) web.WriteFile() log.Fatal("webserver not ready, add key to trusted list ", pull.PublicKey) } log.Println(testserver) log.Println(web) log.Println("Connect") testserver.Connect() web.Connect() err = testserver.Resource("testserverData").Write("Hello") dieOnErr(err) out, err := web.Resource("testserverData").Read() dieOnErr(err) log.Println("Got:", out) }
func main() { dcams.ManifestFileName = "springdata.manifest" testserver, err := dcams.Open() if err != nil { //What do we need: 1 pub, 1 REP pub, err := dcams.NewPub("springData") dieOnErr(err) testserver.Add(pub) REP, err := dcams.NewREP("springInput") dieOnErr(err) testserver.Add(REP) testserver.WriteFile() log.Printf("springdata publish key: [\"%s\"]", pub.PublicKey) log.Printf("springInput REP key: [\"%s\"]", REP.PublicKey) log.Fatal("Manually swap keys with remote client trusted list!") } //log.Println(testserver) log.Println("Connect") testserver.Connect() go handleClientChange(testserver) var c Map dieOnErr(c.readData("http://localhost:9000/public/rsrc/substations.json")) log.Println("Fake data forever") for i := 0; ; i++ { select { case _ = <-time.After(time.Millisecond * 500): msg := c.nextEvent() mmsg, _ := json.Marshal(msg) //log.Println(string(mmsg)) //fmt.Printf(".") err := testserver.Resource("springData").Write(string(mmsg)) dieOnErr(err) case e := <-publish: //log.Println("Got", e) c.SetfrqByName(e.Id, e.Frq) } } }
//connect and read all data published by the simulation side of things func eventsClient() { dcams.ManifestFileName = "web.manifest" web, err := dcams.Open() if err != nil { //What do we need: 1 sub, 1 REQ sub, err := dcams.NewSub("springData") dieOnErr(err) web.Add(sub) REQ, err := dcams.NewREQ("springInput") dieOnErr(err) web.Add(REQ) web.WriteFile() log.Printf("springdata subscribe key: [\"%s\"]", sub.PublicKey) log.Printf("springdata REQ key: [\"%s\"]", REQ.PublicKey) log.Println("Manually swap keys with remote client trusted list!") return //skips the connect } web.Connect() // handles messages coming from user go eventRequester(web) //handles messages going to users. Each websocket reads the publish for { mNodeState, err := web.Resource("springData").Read() if err != nil { continue } var newdata Nodes if err := json.Unmarshal([]byte(mNodeState), &newdata); err != nil { //ignore things that arent Nodess marshalled as json continue } //log.Println(NodeState) publish <- newdata } }