當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。