當前位置: 首頁>>代碼示例>>Golang>>正文


Golang jsonrpc.ServeConn函數代碼示例

本文整理匯總了Golang中net/rpc/jsonrpc.ServeConn函數的典型用法代碼示例。如果您正苦於以下問題:Golang ServeConn函數的具體用法?Golang ServeConn怎麽用?Golang ServeConn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ServeConn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	math := new(Math)
	rpc.Register(math)

	tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
	if err != nil {
		fmt.Println("Fata error:", err)
		os.Exit(2)
	}

	listener, err := net.ListenTCP("tcp", tcpAddr)
	if err != nil {
		fmt.Println("Fata error:", err)
		os.Exit(2)
	}

	for {
		conn, err := listener.Accept()
		if err != nil {
			fmt.Println("conn error:", err)
			continue
		}
		jsonrpc.ServeConn(conn)
	}
}
開發者ID:pengswift,項目名稱:go-test,代碼行數:25,代碼來源:server.go

示例2: main

// Main function
func main() {

	loadConfig()
	loadDict3()
	fingertable = make(map[int]NodeInfo)
	next = 0
	if entrypt == "null" {
		createChordRing()
	} else {
		joinChordRing(entrypt)
	}

	stabilize()
	check_predecessor()
	fixFingers()

	getDict3FromSuccessor()

	dic3 := new(DIC3)
	rpc.Register(dic3)

	tcpAddr, err := net.ResolveTCPAddr(protocol, port)
	checkError(err)
	fmt.Println("Server started........")
	listener, err := net.ListenTCP(protocol, tcpAddr)
	checkError(err)

	for {
		conn, err := listener.Accept()
		if err != nil {
			continue
		}
		jsonrpc.ServeConn(conn)
	}
}
開發者ID:TilakNeha,項目名稱:TripletStoreChord,代碼行數:36,代碼來源:JsonDict3Server.go

示例3: main

// This example demonstrates a trivial echo server.
func main() {
	adder := &Adder{0}

	// Reset the counter every 30 seconds
	go func() {
		c := time.Tick(30 * time.Second)
		for _ = range c {
			adder.Reset()
		}
	}()

	// register our adder (adds the exposed methods)
	// set the http server to use /rpc as the websocket endpoint
	rpc.Register(adder)
	http.Handle("/rpc", websocket.Handler(func(ws *websocket.Conn) {
		jsonrpc.ServeConn(ws)
	}))

	// Serve static files
	http.Handle("/", http.FileServer(http.Dir(".")))
	err := http.ListenAndServe(":12345", nil)
	if err != nil {
		panic("ListenAndServe: " + err.Error())
	}
}
開發者ID:theepicsnail,項目名稱:gowsrpc,代碼行數:26,代碼來源:main.go

示例4: main

func main() {
	fmt.Println("Starting Server...")

	winProc := new(Win32_Process)
	rpc.Register(winProc)

	winSvc := new(Win32_Service)
	rpc.Register(winSvc)

	//setup IP, port for the server
	tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
	checkError(err)

	//start to listen
	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	fmt.Println("Server Started")

	for {
		conn, err := listener.Accept()
		if err != nil {
			continue
		}
		jsonrpc.ServeConn(conn)
	}
}
開發者ID:iamxeph,項目名稱:golang,代碼行數:27,代碼來源:jsonrpcserver.go

示例5: main

func main() {
	// Create Babel service objects
	svc := new(gen.UserService)
	svc.SvcObj = NewUserServiceImpl()

	// Register the service with RPC
	rpc.Register(svc)

	// Register the service with Babel
	babel.Register(svc)

	// Set up Babel HTTP handlers and serve HTTP
	babel.HandleHTTP()
	http.Handle("/test/", http.StripPrefix("/test/", http.FileServer(http.Dir("../test"))))
	go func() { log.Fatal(http.ListenAndServe(":8333", nil)) }()

	//rpc.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath)

	// set up network listener for json rpc
	l, e := net.Listen("tcp", ":8222")
	if e != nil {
		log.Fatal("listen error:", e)
	}

	for {
		conn, err := l.Accept()
		if err != nil {
			log.Fatal(err)
		}

		go jsonrpc.ServeConn(conn)
	}
}
開發者ID:babelrpc,項目名稱:lib-go,代碼行數:33,代碼來源:babjs.go

示例6: ServeHTTP

func (s *Server) ServeHTTP(addr string, jsonRPCURL string, wsRPCURL string, useBasicAuth bool, userList map[string]string) {
	if s.rpcEnabled && jsonRPCURL != "" {
		s.httpEnabled = true
		Logger.Info("<HTTP> enabling handler for JSON-RPC")
		if useBasicAuth {
			http.HandleFunc(jsonRPCURL, use(handleRequest, basicAuth(userList)))
		} else {
			http.HandleFunc(jsonRPCURL, handleRequest)
		}
	}

	if s.rpcEnabled && wsRPCURL != "" {
		s.httpEnabled = true
		Logger.Info("<HTTP> enabling handler for WebSocket connections")
		wsHandler := websocket.Handler(func(ws *websocket.Conn) {
			jsonrpc.ServeConn(ws)
		})
		if useBasicAuth {
			http.HandleFunc(wsRPCURL, use(func(w http.ResponseWriter, r *http.Request) {
				wsHandler.ServeHTTP(w, r)
			}, basicAuth(userList)))
		} else {
			http.Handle(wsRPCURL, wsHandler)
		}
	}

	if !s.httpEnabled {
		return
	}
	if useBasicAuth {
		Logger.Info("<HTTP> enabling basic auth")
	}
	Logger.Info(fmt.Sprintf("<HTTP> start listening at <%s>", addr))
	http.ListenAndServe(addr, nil)
}
開發者ID:cgrates,項目名稱:cgrates,代碼行數:35,代碼來源:server.go

示例7: Start

func Start(conn *CGRConnector, user, pass string) {
	connector = conn
	username = user
	password = pass
	templates = template.Must(template.ParseGlob("templates/*.tmpl"))

	rpc.Register(conn)

	goji.Get(LOGIN_PATH, loginGet)
	goji.Post(LOGIN_PATH, loginPost)

	goji.Get("/app/*", http.FileServer(http.Dir("./static")))

	auth := web.New()
	goji.Handle("/*", auth)
	auth.Use(SessionAuth)
	auth.Handle("/ws", websocket.Handler(func(ws *websocket.Conn) {
		jsonrpc.ServeConn(ws)
	}))
	auth.Post("/import/", importPost)
	auth.Post("/exportcdrs/", exportCdrsPost)
	auth.Post("/exporttpcsv/", exportTpToCsvPost)
	auth.Get("/accounts/logout", logoutGet)
	auth.Get("/", http.RedirectHandler("/app/", 301))
}
開發者ID:MartinChenjq,項目名稱:cgradmin,代碼行數:25,代碼來源:cgradmin.go

示例8: ServeJSON

func (s *Server) ServeJSON(addr string) {
	if !s.rpcEnabled {
		return
	}
	lJSON, e := net.Listen("tcp", addr)
	if e != nil {
		log.Fatal("ServeJSON listen error:", e)
	}
	Logger.Info(fmt.Sprintf("Starting CGRateS JSON server at <%s>.", addr))
	errCnt := 0
	var lastErrorTime time.Time
	for {
		conn, err := lJSON.Accept()
		if err != nil {
			Logger.Err(fmt.Sprintf("<CGRServer> JSON accept error: <%s>", err.Error()))
			now := time.Now()
			if now.Sub(lastErrorTime) > time.Duration(5*time.Second) {
				errCnt = 0 // reset error count if last error was more than 5 seconds ago
			}
			lastErrorTime = time.Now()
			errCnt += 1
			if errCnt > 50 { // Too many errors in short interval, network buffer failure most probably
				break
			}
			continue
		}
		//utils.Logger.Info(fmt.Sprintf("<CGRServer> New incoming connection: %v", conn.RemoteAddr()))
		go jsonrpc.ServeConn(conn)
	}

}
開發者ID:rinor,項目名稱:cgrates,代碼行數:31,代碼來源:server.go

示例9: Start

func Start() {
	// Start the server and accept connections on a
	// UNIX domain socket.
	rpc.Register(quartz)
	listener, err := net.Listen("unix", socketPath)
	if err != nil {
		panic(err)
	}
	for {
		conn, err := listener.Accept()
		if err != nil {
			panic(err)
		}
		go jsonrpc.ServeConn(conn)
	}

	// Destroy the socket file when the server is killed.
	sigc := make(chan os.Signal)
	signal.Notify(sigc, syscall.SIGTERM)
	go func() {
		<-sigc
		err := listener.Close()
		if err != nil {
			panic(err)
		}
		os.Exit(0)
	}()
}
開發者ID:ashish173,項目名稱:quartz,代碼行數:28,代碼來源:quartz.go

示例10: start

func (w *WebServer) start(host string) {
	http.HandleFunc("/ws-server",
		func(w http.ResponseWriter, req *http.Request) {
			s := websocket.Server{
				Handler: websocket.Handler(func(ws *websocket.Conn) {
					jsonrpc.ServeConn(ws)
				}),
			}
			s.ServeHTTP(w, req)
			log.Println("connected ws-server")
		})
	http.HandleFunc("/ws-client",
		func(rw http.ResponseWriter, req *http.Request) {
			s := websocket.Server{
				Handler: websocket.Handler(func(ws *websocket.Conn) {
					w.client = jsonrpc.NewClient(ws)
					w.ch <- struct{}{}
					<-w.ch
				}),
			}
			s.ServeHTTP(rw, req)
			log.Println("connected ws-client")
		})
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, r.URL.Path[1:])
	})
	if err := http.ListenAndServe(host, nil); err != nil {
		log.Fatal(err)
	}
}
開發者ID:lacion,項目名稱:wsrpc,代碼行數:30,代碼來源:webserver.go

示例11: serverFun

func serverFun(serverInfo1 ServerConfig) {
	fmt.Println("Server Function started")
	//server start
	dictionaryFile = serverInfo1.PersistentStorageContainer

	dict3 := new(DICT3)
	rpc.Register(dict3)
	clientAddr, err := net.ResolveTCPAddr(serverInfo1.Protocol, ":"+strconv.Itoa(serverInfo1.MyPort))
	if err != nil {
		fmt.Println("Error1: ", err.Error)
		os.Exit(1)
	}
	listn, err := net.ListenTCP(serverInfo1.Protocol, clientAddr)
	if err != nil {
		fmt.Println("Error2: ", err.Error)
		os.Exit(1)
	}
	ReadFile(dictionaryFile) //load to map

	for {
		connect, err := listn.Accept()
		if err != nil {
			continue
		}
		go func() {
			jsonrpc.ServeConn(connect)
		}()
	}
}
開發者ID:diganth1,項目名稱:ChordProtocol_Golang,代碼行數:29,代碼來源:Final_Server.go

示例12: main

func main() {
	db, e := sql.Open("mysql", "[email protected]/scan?charset=utf8")
	defer db.Close()
	if e != nil {
		fmt.Println("Не удалось подключится к БД: ", e)
	}

	bs := new(storage.BlockStorage)
	bs.DB = db
	is := new(storage.IpStorage)
	is.DB = db

	rpc.Register(bs)
	rpc.Register(is)

	tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	for {
		conn, err := listener.Accept()
		if err != nil {
			continue
		}
		go func(conn net.Conn) {
			jsonrpc.ServeConn(conn)
			//			conn.CloseWrite()
		}(conn)

	}
}
開發者ID:vyegres,項目名稱:nscaner,代碼行數:33,代碼來源:main.go

示例13: BenchmarkJSONRPC_pipe

func BenchmarkJSONRPC_pipe(b *testing.B) {
	cli, srv := net.Pipe()
	go jsonrpc.ServeConn(srv)
	client := jsonrpc.NewClient(cli)
	defer client.Close()
	benchmarkRPC(b, client)
}
開發者ID:plumbum,項目名稱:rpc-codec,代碼行數:7,代碼來源:bench_test.go

示例14: main

func main() {
	manager := new(TaskManager)
	rpc.Register(manager)

	tcpAddr, err := net.ResolveTCPAddr("tcp", ":8080")

	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	listener, err := net.ListenTCP("tcp", tcpAddr)
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	for {
		conn, err := listener.Accept()
		if err != nil {
			continue
		}

		go jsonrpc.ServeConn(conn)

	}
}
開發者ID:ShaorxCN,項目名稱:myStudy,代碼行數:27,代碼來源:main.go

示例15: main

func main() {

	arith := new(Arith)
	rpc.Register(arith)

	tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	/* This works:
	rpc.Accept(listener)
	*/
	/* and so does this:
	 */
	for {
		conn, err := listener.Accept()
		if err != nil {
			continue
		}
		jsonrpc.ServeConn(conn)
	}

}
開發者ID:alvalea,項目名稱:go-rpc,代碼行數:25,代碼來源:server.go


注:本文中的net/rpc/jsonrpc.ServeConn函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。