本文整理汇总了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)))
}
}
示例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))
}
示例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)))
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
}
示例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)
}
示例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
}
示例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)))
}
示例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)))
}
}()
}
示例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))
}
}()
}
示例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)))
}
}
示例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)
}
}
}