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


Golang Server.ServeCodec方法代码示例

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


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

示例1: ConnectServer

func ConnectServer(addr string, s *rpc.Server) error {
	if conn, err := net.Dial("tcp", addr); err == nil {
		s.ServeCodec(NewServerCodec(conn))
	} else {
		return err
	}
	return nil
}
开发者ID:petemoore,项目名称:rpc4,代码行数:8,代码来源:connect.go

示例2: Serve

func Serve(s *rpc.Server, l net.Listener) {
	for {
		conn, err := l.Accept()
		if err != nil {
			log.Fatal("rpc.Serve: accept:", err.Error())
		}
		go s.ServeCodec(NewServerCodec(conn))
	}
}
开发者ID:ironzhang,项目名称:golang,代码行数:9,代码来源:server.go

示例3: ServeMsgpack

func ServeMsgpack(l net.Listener, s *rpc.Server) error {
	for {
		conn, err := l.Accept()
		if err != nil {
			return err
		}
		codec := codec.MsgpackSpecRpc.ServerCodec(conn, &msgpackHandle)
		go s.ServeCodec(codec)
	}
}
开发者ID:icexin,项目名称:raftkv,代码行数:10,代码来源:msgpack.go

示例4: ServeRedis

func ServeRedis(l net.Listener, s *rpc.Server) error {
	for {
		conn, err := l.Accept()
		if err != nil {
			return err
		}
		codec := NewRedisServerCodec(conn)
		go s.ServeCodec(codec)
	}
}
开发者ID:icexin,项目名称:raftkv,代码行数:10,代码来源:redis.go

示例5: handle

//function for handling RPC connection
func handle(server *rpc.Server, conn net.Conn) {
	fmt.Println("start handle")
	//defer conn.Close() //make sure connection gets closed
	remote := conn.RemoteAddr().String() + " --> " + conn.LocalAddr().String()
	fmt.Println("==conn " + remote)
	//requests
	//doRequests(conn)
	// time.Sleep(3 * time.Second)

	fmt.Println("==conn " + remote)
	server.ServeCodec(jsonrpc.NewServerCodec(conn))
	fmt.Println("==discon " + remote)
	fmt.Println("end handle")
}
开发者ID:jmptrader,项目名称:jsonrpc,代码行数:15,代码来源:tcptestclient.go

示例6: waitForConnections

func (c *Simple) waitForConnections(rpcs *rpc.Server) {
	for {
		conn, err := c.listener.Accept()
		if err == nil {
			if *use_codec {
				//rpcCodec := codec.GoRpc.ServerCodec(conn, &mh)
				rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, &mh)
				go rpcs.ServeCodec(rpcCodec)
			} else {
				go rpcs.ServeConn(conn)
			}
		} else {
			// handle error
			//fmt.Println("ERROR: ", err)
		}
	}
}
开发者ID:narula,项目名称:bench,代码行数:17,代码来源:simple-server.go

示例7: handleConnection

func (s *Server) handleConnection(conn net.Conn) {
	// We create a new server each time so that we can have access to the
	// underlying connection. The standard rpc package does not give us access
	// to the calling connection :/
	var server *rpc.Server = rpc.NewServer()

	// Get a free service from the pool.
	var service *Discovery
	select {
	case service = <-s.servicePool:
		// Success
	default:
		service = newDiscoveryService(s)
	}

	// Set up the service variables.
	service.init(conn, atomic.AddInt32(&s.nextConnId, 1))

	// If debugging is enabled, log all rpc traffic.
	var rwc io.ReadWriteCloser = conn
	if *debug {
		rwc = &debugInput{conn}
	}

	// Set up the rpc service and start serving the connection.
	server.Register(service)
	server.ServeCodec(jsonrpc.NewServerCodec(rwc))

	// Connection has disconnected. Remove any registered services.
	s.removeAll(service)

	// Reset the service state.
	service.init(nil, -1)

	select {
	case s.servicePool <- service:
		// Success
	default:
		// Buffer is full
	}
}
开发者ID:croachrose,项目名称:discovery,代码行数:41,代码来源:server.go

示例8: Server

func Server() {
	var err error
	var l net.Listener
	l, err = net.Listen("tcp", ":1234")
	if err != nil {
		log.Fatal("listen error:", err)
	}
	defer l.Close()
	var s *rpc.Server
	s = rpc.NewServer()
	s.Register(new(Arith))
	for {
		var err error
		var c net.Conn
		c, err = l.Accept()
		log.Println(c.RemoteAddr())
		if err != nil {
			log.Fatal("listen error:", err)
		}
		go s.ServeCodec(jsonrpc.NewServerCodec(c))
	}
}
开发者ID:fengzai,项目名称:snippet,代码行数:22,代码来源:rpc-server.go

示例9: handle


//.........这里部分代码省略.........
			encoder.Encode(err.Error())
			return
		}

		// Grab our client.
		client, err := control.Ready()
		if err != nil {
			encoder.Encode(err.Error())
			return
		}

		// Call start.
		result := noguest.StartResult{}
		err = client.Call("Server.Start", &start, &result)
		if err != nil {
			encoder.Encode(err.Error())
			return
		}

		// Save our pid.
		pid := result.Pid
		inputs := make(chan error)
		outputs := make(chan error)
		exitcode := make(chan int)

		// This indicates we're okay.
		encoder.Encode(nil)

		// Wait for the process to exit.
		go func() {
			wait := noguest.WaitCommand{
				Pid: pid,
			}
			var wait_result noguest.WaitResult
			err := client.Call("Server.Wait", &wait, &wait_result)
			if err != nil {
				exitcode <- 1
			} else {
				exitcode <- wait_result.Exitcode
			}
		}()

		// Read from stdout & stderr.
		go func() {
			read := noguest.ReadCommand{
				Pid: pid,
				N:   4096,
			}
			var read_result noguest.ReadResult
			for {
				err := client.Call("Server.Read", &read, &read_result)
				if err != nil {
					inputs <- err
					return
				}
				err = encoder.Encode(read_result.Data)
				if err != nil {
					inputs <- err
					return
				}
			}
		}()

		// Write to stdin.
		go func() {
			write := noguest.WriteCommand{
				Pid: pid,
			}
			var write_result noguest.WriteResult
			for {
				err := decoder.Decode(&write.Data)
				if err != nil {
					outputs <- err
					return
				}
				err = client.Call("Server.Write", &write, &write_result)
				if err != nil {
					outputs <- err
					return
				}
			}
		}()

		// Wait till exit.
		status := <-exitcode
		encoder.Encode(status)

		// Wait till EOF.
		<-inputs

		// Send a notice and close the socket.
		encoder.Encode(nil)

	} else if header == "NOVM RPC\n" {

		// Run as JSON RPC connection.
		codec := jsonrpc.NewServerCodec(control_file)
		server.ServeCodec(codec)
	}
}
开发者ID:XenServerBestPractice,项目名称:novm,代码行数:101,代码来源:server.go


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