当前位置: 首页>>代码示例>>Golang>>正文


Golang rpc.ServeCodec函数代码示例

本文整理汇总了Golang中net/rpc.ServeCodec函数的典型用法代码示例。如果您正苦于以下问题:Golang ServeCodec函数的具体用法?Golang ServeCodec怎么用?Golang ServeCodec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ServeCodec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	scribeService := new(scribeServiceImplementation)
	rpc.RegisterName("Thrift", &scribe.ScribeServer{Implementation: scribeService})
	flag.IntVar(&port, "p", 1463, "Scribe Listen Port")
	flag.StringVar(&kafka_hostname, "o", "localhost:9092", "host:port string for the kafka server")
	flag.IntVar(&partition, "r", 1, "partition to publish to")
	flag.IntVar(&buffer_size, "s", 10, "Buffer Size")
	flag.IntVar(&buffer_time, "t", 10, "Buffer Time")

	flag.Parse()

	fmt.Printf("Quiet! I'm trying to listen to port %d and send to kafka at %s", port, kafka_hostname)
	ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
	if err != nil {
		log.Println(err)
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			fmt.Printf("ERROR: %+v\n", err)
			continue
		}
		fmt.Printf("New connection %+v\n", conn)
		go rpc.ServeCodec(thrift.NewServerCodec(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false)))
	}
}
开发者ID:siliconcow,项目名称:scribe_kafka_translator,代码行数:26,代码来源:skt.go

示例2: main

func main() {
	bind_addr := flag.String("bind_ip", "127.0.0.1", "bind ip address")
	http_port := flag.Int("http_port", 9999, "listen http port")
	rpc_port := flag.Int("rpc_port", 9998, "listen rpc port")
	flag.Parse()

	go func() {
		addr, _ := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", *bind_addr, *rpc_port))
		listener, _ := net.ListenTCP("tcp", addr)
		rpcservice := new(RPCService)
		rpc.Register(rpcservice)
		rpc.HandleHTTP()
		for {
			conn, _ := listener.Accept()
			go rpc.ServeCodec(jsonrpc.NewServerCodec(conn))
		}
	}()

	web.Get("/api/topics/([a-zA-Z0-9_\\-]+)/subscribers/([a-zA-Z0-9_\\-]+)/messages", APIGetTopicMessages)
	web.Post("/api/topics/([a-zA-Z0-9_\\-]+)/subscribers/([a-zA-Z0-9_\\-]+)/messages", APIPostTopicMessage)
	web.Get("/api/topics/([a-zA-Z0-9_\\-]+)", APIGetTopic)
	web.Post("/api/topics/([a-zA-Z0-9_\\-]+)", APIUpdateTopic)
	//web.Get("/api/topics", APIGetTopics)
	web.Get("/api/subscribers/([a-zA-Z0-9_\\-]+)", APIGetSubscriber)
	web.Post("/api/subscribers/([a-zA-Z0-9_\\-]+)", APIUpdateSubscriber)
	//web.Get("/api/topics/(.+)/subscribers/(.+)", APIGetTopicSubscriber)
	//web.Get("/api/topics/(.+)/subscribers", APIGetTopicSubscribers)

	web.Run(fmt.Sprintf("%s:%d", *bind_addr, *http_port))

}
开发者ID:jahrain,项目名称:gmb,代码行数:31,代码来源:mbroker.go

示例3: ServeHTTP

func (self *rpcHandler) ServeHTTP(c http.ResponseWriter, req *http.Request) {
	conn, _, err := c.(http.Hijacker).Hijack()
	if err != nil {
		relog.Error("rpc hijacking %s: %v", req.RemoteAddr, err)
		return
	}
	io.WriteString(conn, "HTTP/1.0 "+connected+"\n\n")
	rpc.ServeCodec(self.cFactory(NewBufferedConnection(conn)))
}
开发者ID:seacoastboy,项目名称:vitess,代码行数:9,代码来源:rpcwrap.go

示例4: Accept

func (svr *server) Accept() {
	conn, _ := svr.ln.Accept()

	svr.cn = conn
	log.Println("using custom codec for server")
	//rpcCodec := msgpack.NewCustomRPCServerCodec(conn, nil)
	rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h)
	go rpc.ServeCodec(rpcCodec)
}
开发者ID:nrml,项目名称:rpc-go,代码行数:9,代码来源:server.go

示例5: StartRPC

func StartRPC(url, queue string) {
	rpc.Register(new(Fumble))
	conn, err := amqp.Dial(url)
	if err != nil {
		log.Fatal(err)
	}

	serverCodec, err := amqprpc.NewServerCodec(conn, queue, amqprpc.JSONCodec{})
	rpc.ServeCodec(serverCodec)
}
开发者ID:TF2Stadium,项目名称:Fumble,代码行数:10,代码来源:rpc.go

示例6: runPipeServer

func runPipeServer(protoDebug bool) {
	protocol := new(protocol.Protocol)
	rpc.Register(protocol)
	pp, err := createPipePair(os.Stdin, os.Stdout, protoDebug)
	if err != nil {
		logger.Warning(fmt.Sprintf("Failed to create pipe pair: %s", err))
		return
	}
	codec := jsonrpc.NewServerCodec(pp)
	logger.Info("Starting...")
	rpc.ServeCodec(codec)
}
开发者ID:nymsio,项目名称:nyms-agent,代码行数:12,代码来源:pipes.go

示例7: ExampleNewServerCodec

func ExampleNewServerCodec() {
	conn, err := amqp.Dial("amqp://guest:[email protected]:5672/")
	if err != nil {
		log.Fatal(err)
	}

	serverCodec, err := amqprpc.NewServerCodec(conn, "rpc_queue", amqprpc.GobCodec{})
	if err != nil {
		log.Fatal(err)
	}

	go rpc.ServeCodec(serverCodec)
}
开发者ID:vibhavp,项目名称:amqp-rpc,代码行数:13,代码来源:example_test.go

示例8: runServer

func runServer(port string) {
	// Set processor
	rpc.RegisterName("Thrift", &echo.EchoServer{Implementation: new(echoHandler)})
	ln, _ := net.Listen("tcp", port)

	for {
		conn, _ := ln.Accept()
		go func(c net.Conn) {
			t := thrift.NewTransport(thrift.NewFramedReadWriteCloser(c, 0), thrift.BinaryProtocol)
			rpc.ServeCodec(thrift.NewServerCodec(t))
		}(conn)
	}
}
开发者ID:ryyan,项目名称:thrift-benchmark,代码行数:13,代码来源:server.go

示例9: myAccept

func myAccept(l net.Listener) {
	conn, err := l.Accept()
	if err != nil {
		fmt.Println("Accept error: ", err)
		return
	}

	// 创建一个自定义的ServerCode, 实际上这些代码就从go源码中获取出来的
	buf := bufio.NewWriter(conn)
	codec := &myServerCodec{conn, gob.NewDecoder(conn), gob.NewEncoder(buf), buf}

	//运行连接
	go rpc.ServeCodec(codec)
}
开发者ID:upccup,项目名称:cuplearn,代码行数:14,代码来源:servecodec.go

示例10: server

// Start up the RPC Server
func server(registry *Registry, port int) error {
	rpc.Register(registry)
	rpc.HandleHTTP()
	ln, err := net.Listen("tcp", util.Address("", port))
	if err != nil {
		return err
	}
	go func() {
		for {
			conn, _ := ln.Accept()
			rpc.ServeCodec(jsonrpc.NewServerCodec(conn))
		}
	}()
	return nil
}
开发者ID:paulbellamy,项目名称:gossip,代码行数:16,代码来源:gossip.go

示例11: ServeHTTP

func (self *rpcHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	if req.Method != "CONNECT" {
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
		w.WriteHeader(http.StatusMethodNotAllowed)
		io.WriteString(w, "405 must CONNECT\n")
		return
	}
	conn, _, err := w.(http.Hijacker).Hijack()
	if err != nil {
		log.Printf("rpc hijacking %s: %v", req.RemoteAddr, err)
		return
	}
	io.WriteString(conn, "HTTP/1.0 "+connected+"\n\n")
	rpc.ServeCodec(self.cFactory(NewBufferedConnection(conn)))
}
开发者ID:notedit,项目名称:bsonrpc,代码行数:15,代码来源:server.go

示例12: startServer

func startServer() {
	rpc.RegisterName("Thrift", new(TestService))

	var l net.Listener
	l, serverAddr = listenTCP()
	log.Println("Test RPC server listening on", serverAddr)
	go func() {
		for {
			conn, err := l.Accept()
			if err != nil {
				panic(err)
			}
			go rpc.ServeCodec(NewServerCodec(NewFramedReadWriteCloser(conn, 0), NewBinaryProtocol(true, false)))
		}
	}()
}
开发者ID:jimmysawczuk,项目名称:go-thrift,代码行数:16,代码来源:client_test.go

示例13: startRPCServer

// startRPCServer registers the master consumer for plugins. The master consumer allows plugins to
// communicate with the bot, allowing access to connected channels, users and registered modules.
// Conventionally, it uses a json codec to serve.
func (b *Bot) startRPCServer() {
	rpc.RegisterName("Master", BotAPI{b})
	master, err := net.Listen("tcp", ":0")
	b.ListenPort = strconv.Itoa(master.Addr().(*net.TCPAddr).Port)
	rlog.Info("Bot", "Listening on port: "+b.ListenPort)

	if err != nil {
		rlog.Error("Bot", err.Error())
	}

	// Start accepting connections
	go func() {
		for {
			conn, _ := master.Accept()
			go rpc.ServeCodec(RpcCodecServer(conn))
		}
	}()
}
开发者ID:raindevteam,项目名称:rain,代码行数:21,代码来源:bot.go

示例14: main

func main() {
	scribeService := new(scribeServiceImplementation)
	rpc.RegisterName("Thrift", &scribe.ScribeServer{scribeService})

	ln, err := net.Listen("tcp", ":1463")
	if err != nil {
		panic(err)
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			fmt.Printf("ERROR: %+v\n", err)
			continue
		}
		fmt.Printf("New connection %+v\n", conn)
		go rpc.ServeCodec(thrift.NewServerCodec(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false)))
	}
}
开发者ID:nairboon,项目名称:go-thrift,代码行数:18,代码来源:main.go

示例15: Run

func Run(mdmanager *metadata.Manager) {
	fmt.Print("Runnig server\n")

	handler.RegisterAll(mdmanager)
	ln, err := net.Listen("tcp", fmt.Sprintf(":%d", aether.DEFAULT_PORT))

	if err != nil {
		panic(fmt.Sprintf("Error %s", err))
	}

	for {
		conn, err := ln.Accept()
		if err == nil {
			rpcCodec := msgpack.NewRPCServerCodec(conn, nil)
			rpc.ServeCodec(rpcCodec)
		}

	}
}
开发者ID:cyraxjoe,项目名称:aether,代码行数:19,代码来源:actions.go


注:本文中的net/rpc.ServeCodec函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。