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