本文整理汇总了Golang中net/rpc.Accept函数的典型用法代码示例。如果您正苦于以下问题:Golang Accept函数的具体用法?Golang Accept怎么用?Golang Accept使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Accept函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
// Initialise Server, registering RPC service and binding to port 1234
func (t *Server) init() {
t.Status = true
rpc.Register(t)
tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
t.checkError(err)
listener, err := net.ListenTCP("tcp", tcpAddr)
t.checkError(err)
// create new map for tracking routes
t.Routes = make(map[int][]*Tram)
t.Clients = make(map[string]*Record)
rpc.Accept(listener)
// case want to add additional socket accounting
// for {
// conn, err := listener.Accept()
// if err != nil {
// continue
// }
// rpc.ServeConn(conn)
// }
}
示例2: main
func main() {
flag.Parse()
rpc.Register(new(Worker))
l, e := net.Listen("tcp", ":"+strconv.Itoa(*port))
if e != nil {
log.Fatal("listen error:", e)
}
log.Print("listening for connections on ", l.Addr())
if *connect != "" {
log.Printf("calling %s\n", *connect)
conn, err := net.Dial("tcp", *connect)
if err != nil {
log.Fatalf("failed to connect to %s: %s", *connect, err)
}
addr, _, err := net.SplitHostPort(conn.LocalAddr().String())
if err != nil {
log.Fatalf("failed to get the local address: %s", err)
}
laddr := net.JoinHostPort(addr, strconv.Itoa(*port))
client := rpc.NewClient(conn)
var res struct{}
client.Call("WorkerList.Add", laddr, &res)
client.Close()
}
rpc.Accept(l)
}
示例3: clusterInit
func clusterInit(configString json.RawMessage) {
if globals.cluster != nil {
log.Fatal("Cluster already initialized")
}
// This is a standalone server, not initializing
if configString == nil || len(configString) == 0 {
log.Println("Running as a standalone server.")
return
}
var config ClusterConfig
if err := json.Unmarshal(configString, &config); err != nil {
log.Fatal(err)
}
globals.cluster = &Cluster{
thisNodeName: config.ThisName,
ring: rh.New(CLUSTER_HASH_REPLICAS, nil),
nodes: make(map[string]*ClusterNode)}
ringKeys := make([]string, 0, len(config.Nodes))
for _, host := range config.Nodes {
ringKeys = append(ringKeys, host.Name)
if host.Name == globals.cluster.thisNodeName {
// Don't create a cluster member for this local instance
continue
}
n := ClusterNode{address: host.Addr, name: host.Name}
n.done = make(chan bool, 1)
go n.reconnect()
globals.cluster.nodes[host.Name] = &n
}
if len(globals.cluster.nodes) == 0 {
log.Fatal("Invalid cluster size: 0")
}
globals.cluster.ring.Add(ringKeys...)
addr, err := net.ResolveTCPAddr("tcp", config.ListenOn)
if err != nil {
log.Fatal(err)
}
globals.cluster.inbound, err = net.ListenTCP("tcp", addr)
if err != nil {
log.Fatal(err)
}
rpc.Register(globals.cluster)
go rpc.Accept(globals.cluster.inbound)
log.Printf("Cluster of %d nodes initialized, node '%s' listening on [%s]", len(globals.cluster.nodes)+1,
globals.cluster.thisNodeName, config.ListenOn)
}
示例4: StartServer
// StartServer starts the HTTP RPC server
func StartServer() {
l, e := net.Listen("tcp", "0.0.0.0:1234") // FIXME get port from config file
if e != nil {
log.Fatal("listen error:", e)
}
// this serves endless
rpc.Accept(l)
}
示例5: StartServer
// StartServer runs the endless rpc server FIX TLS needed
func StartServer() {
l, e := net.Listen("tcp", "0.0.0.0:"+port)
if e != nil {
log.Fatal("listen error:", e)
}
// this serves endless
rpc.Accept(l)
}
示例6: start
// start of RPC server
func (rpcs *RPCServer) start(addr string) {
listen, e := net.Listen("tcp", addr)
if e != nil {
log.Fatal("listen error:", e)
}
rpcs.listen = listen
rpc.Accept(rpcs.listen)
}
示例7: startRpc
func startRpc() net.Listener {
lis, err := net.Listen("tcp", net.JoinHostPort("", strconv.Itoa(RpcPort)))
if err != nil {
log.Fatal("rpc.Start:", err)
}
go rpc.Accept(lis)
return lis
}
示例8: ServeRPC
func ServeRPC() {
rpc.Register(NewRPC())
rpc_on := fmt.Sprintf("%s:%d", config.BindAddress, config.RPCPort)
l, e := net.Listen("tcp", rpc_on)
if e != nil {
log.Fatal("listen error:", e)
}
rpc.Accept(l)
}
示例9: startAdders
// StartAdders registers the jobadder and accepts
// incoming connections
func startAdders(joblist *joblist) {
jobAdder := JobAdder{joblist}
rpc.Register(&jobAdder)
l, err := net.Listen("tcp", ":"+strconv.Itoa(*cmdport))
if err != nil {
logfile.Fatal("listen error:", err)
}
logfile.Print("listening for new commands on ", l.Addr())
go rpc.Accept(l)
}
示例10: main
func main() {
rpc.Register(NewRPC())
l, e := net.Listen("tcp", ":9876")
if e != nil {
log.Fatal("listen error:", e)
}
rpc.Accept(l)
}
示例11: initCli
func initCli() *rpc.Client {
l, err := net.Listen("tcp", ":11019")
if err != nil {
return nil
}
rpc.RegisterName("Math", new(Math))
go rpc.Accept(l)
cli, _ := rpc.Dial("tcp", ":11019")
return cli
}
示例12: main
func main() {
fmt.Println("Starting up RPC server...")
server := paperclips.NewRPCServer()
rpc.Register(server)
fmt.Println("Now listening on", address)
l, e := net.Listen("tcp", address)
if e != nil {
log.Fatal("listen error:", e)
}
rpc.Accept(l)
}
示例13: main
func main() {
rpc.Register(rpctime.NewRPC()) // HL
l, err := net.Listen("tcp", ":19876") // HL
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
rpc.Accept(l) // HL
}
示例14: main
func main() {
gobby := new(Gobby)
rpc.Register(gobby)
l, e := net.Listen("tcp", ":1234")
if e != nil {
log.Fatal("listen error:", e)
}
go rpc.Accept(l)
go rawProtocol_refl()
rawProtocol_hand()
}
示例15: startServer
// StartServer starts the HTTP RPC server
func startServer() {
server := new(ServerRpcT)
rpc.Register(server)
l, e := net.Listen("tcp", "localhost:2345") // FIXME get port from config file
if e != nil {
log.Fatal("listen error:", e)
}
// this serves endless
rpc.Accept(l)
}