// 无标识符UID的demo func main() { tp := teleport.New() tp.SetAPI(teleport.API{ "报到": func(receive *teleport.NetData) *teleport.NetData { log.Printf("报到:%v", receive.Body) return teleport.ReturnData("我是服务器,我已经收到你的来信") }, }) tp.Server(":20125") select {} }
// 无标识符UID的demo func main() { tp := teleport.New() tp.SetAPI(teleport.API{ "报到": func(receive *teleport.NetData) *teleport.NetData { log.Printf("报到:%v", receive.Body) return teleport.ReturnData("服务器:"+receive.From+"客户端已经报到!", "报到", "C3") }, // 短链接不可以直接转发请求 "短链接报到": func(receive *teleport.NetData) *teleport.NetData { log.Printf("报到:%v", receive.Body) tp.Request("服务器:"+receive.From+"客户端已经报到!", "报到", "C3") return nil }, }).Server(":20125") select {} }
func (self *task1) Process(receive *teleport.NetData) *teleport.NetData { return teleport.ReturnData(self.Out(self.CountNodes())) }
func (self *masterTaskHandle) Process(receive *teleport.NetData) *teleport.NetData { b, _ := json.Marshal(self.Send(self.CountNodes())) return teleport.ReturnData(string(b)) }
func (self *task1) Process(receive *teleport.NetData) *teleport.NetData { b, _ := json.Marshal(self.Out(self.CountNodes())) return teleport.ReturnData(string(b)) }