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