当前位置: 首页>>代码示例>>Golang>>正文


Golang jsonrpc.Dial函数代码示例

本文整理汇总了Golang中net/rpc/jsonrpc.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Dial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	service := "localhost:1234"
	if len(os.Args) == 2 {
		client, err := jsonrpc.Dial("tcp", service)
		if err != nil {
			log.Fatal("dialing:", err)
		}

		var reply string
		err = client.Call("Stock.GetStockDetails", os.Args[1], &reply)
		if err != nil {
			log.Fatal("stock error:", err)
		}
		fmt.Println(reply)
	}
	if len(os.Args) < 2 {
		fmt.Println("Usage: ", os.Args[0], "server")
		os.Exit(1)
	}
	if len(os.Args) > 2 {

		client, err := jsonrpc.Dial("tcp", service)
		if err != nil {
			log.Fatal("dialing:", err)
		}

		args := Args{os.Args[1], os.Args[2]}
		var reply string
		err = client.Call("Stock.Buy", args, &reply)
		if err != nil {
			log.Fatal("stock error:", err)
		}
		fmt.Println(reply)
	}
}
开发者ID:rskartheek,项目名称:cmpe273-assignment1,代码行数:35,代码来源:client.go

示例2: TestSMGRplcApierRpcConn

// Connect rpc client to rater
func TestSMGRplcApierRpcConn(t *testing.T) {
	if smgRplcMstrRPC, err = jsonrpc.Dial("tcp", smgRplcMasterCfg.RPCJSONListen); err != nil {
		t.Fatal(err)
	}
	if smgRplcSlvRPC, err = jsonrpc.Dial("tcp", smgRplcSlaveCfg.RPCJSONListen); err != nil {
		t.Fatal(err)
	}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:9,代码来源:smgreplc_it_test.go

示例3: main

func main() {
	var i int
	fmt.Println("Put 1 to purchase stocks, 2 to check portfolio, anything else to exit")
	fmt.Scanf("%d", &i)
	switch i {
	case 1:
		fmt.Println("Enter Stock Key & Stock Percentage(E.g. “GOOG:50%,YHOO:50%”)")
		var input string
		fmt.Scanln(&input)

		fmt.Println("Enter Your Budget")
		var budget float32
		fmt.Scanln(&budget)

		client, err := jsonrpc.Dial("tcp", ":1234")
		if err != nil {
			log.Fatal("dialing:", err)
		}
		// Synchronous call
		args := Request{input, budget}
		var reply Response
		err = client.Call("StockDetail.Stocks", &args, &reply)
		if err != nil {
			log.Fatal("stock error", err)
		}
		fmt.Println(reply.TradeId)
		fmt.Println(reply.Stocks)
		fmt.Println(reply.LeftOver)
		break

	case 2:
		fmt.Println("Enter TradeID")
		var id int
		fmt.Scanln(&id)

		fmt.Println(id)

		client, err := jsonrpc.Dial("tcp", ":1234")
		if err != nil {
			log.Fatal("dialing: ", err)
		}
		args := RequestCheck{id}
		var reply ReplyCheck
		err = client.Call("StockDetail.CheckPortfolio", &args, &reply)
		if err != nil {
			log.Fatal("check Error: ", err)
		}
		fmt.Println(reply.StocksC)
		fmt.Println(reply.CurrentMarketValue)
		fmt.Println(reply.LeftAmount)
		break
	default:
		os.Exit(0)

	}

}
开发者ID:MingluLiu,项目名称:assignment1,代码行数:57,代码来源:client.go

示例4: getDict3FromSuccessor

// get DICT3 entries from successor after joining ring
func getDict3FromSuccessor() error {
	if successor.Chordid != chordid {
		client, err := jsonrpc.Dial(protocol, successor.Address)
		if err != nil {
			log.Fatal("dialing:", err)
		}
		var reply2 []string
		req := chordid
		RpcCall := client.Go("DIC3.RPCGetDict3FromSuccessor", req, &reply2, nil)
		replyCall := <-RpcCall.Done
		if replyCall != nil {
		}
		client.Close()

		//iterate through reply2 and insert in my dict3
		for _, triplet := range reply2 {
			arr := strings.Split(triplet, "=")
			if len(arr) == 3 {
				key_rel := DKey{arr[0], arr[1]}
				b := []byte(arr[2])
				var f map[string]interface{}
				err := json.Unmarshal(b, &f)
				if err != nil {
					log.Fatal(err)
				}
				dict3[key_rel] = f
			}
		}
		fmt.Println("Updated my DICT3, added triplets - ", len(dict3))
	}
	return nil
}
开发者ID:TilakNeha,项目名称:TripletStoreChord,代码行数:33,代码来源:JsonDict3Server.go

示例5: testTPitRpcConn

// Connect rpc client to rater
func testTPitRpcConn(t *testing.T) {
	var err error
	tpRPC, err = jsonrpc.Dial("tcp", tpCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
	if err != nil {
		t.Fatal(err)
	}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:8,代码来源:tp_it_test.go

示例6: BenchmarkRpc

func BenchmarkRpc(b *testing.B) {
	var d Daemon
	if err := d.init(); err != nil {
		b.Fatal(err)
	}
	go d.serverloop()
	defer d.close()

	if c, err := jsonrpc.Dial("tcp", fmt.Sprintf("127.0.0.1%s", port)); err != nil {
		b.Error(err)
	} else {
		defer c.Close()

		s := time.Now()
		for i := 0; i < b.N; i++ {
			var a content.CompleteAtArgs
			a.Location.Line = 95
			a.Location.Column = 45
			a.Location.File.Name = "../net/testdata/CompleteSharp.cs"

			var cmp1 content.CompletionResult
			if err := c.Call("Net.CompleteAt", &a, &cmp1); err != nil {
				b.Error(err)
			}
		}
		e := time.Since(s).Seconds() * 1000
		b.Logf("%d calls in %f ms = %f ms/call", b.N, e, e/float64(b.N))
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:29,代码来源:daemon_test.go

示例7: TestFlatstoreitRpcConn

// Connect rpc client to rater
func TestFlatstoreitRpcConn(t *testing.T) {
	var err error
	flatstoreRpc, err = jsonrpc.Dial("tcp", flatstoreCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
	if err != nil {
		t.Fatal("Could not connect to rater: ", err.Error())
	}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:8,代码来源:flatstore_it_test.go

示例8: TestPartcsvITRpcConn

// Connect rpc client to rater
func TestPartcsvITRpcConn(t *testing.T) {
	var err error
	partcsvRPC, err = jsonrpc.Dial("tcp", partcsvCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
	if err != nil {
		t.Fatal("Could not connect to rater: ", err.Error())
	}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:8,代码来源:partialcsv_it_test.go

示例9: Dial

// start a rpc client
// if ok , store if
func (this *RpcClient) Dial(ip string, port int) (*rpc.Client, error) {
	client, err := jsonrpc.Dial(RPC_TYPE, ip+":"+strconv.Itoa(port))
	if err != nil {
		log.Println(err)
	}
	return client, err
}
开发者ID:ROOT005,项目名称:ants-go,代码行数:9,代码来源:client.go

示例10: callPart1

func callPart1() {

	var req Request
	var res Response

	req.StockSymbolAndPercentage = os.Args[1]
	req.Budget, _ = strconv.ParseFloat(os.Args[2], 64)

	client, err := jsonrpc.Dial("tcp", "127.0.0.1:1237")
	if err != nil {
		log.Fatal("dialing:", err)
	}

	err = client.Call("Obj.Part1", req, &res)
	if err != nil {
		log.Fatal("error:", err)
	}

	//printing part1 response

	fmt.Println("\nResponse from server: ")
	fmt.Println("\nTradeId: ", res.TradeId)
	fmt.Println("\nStocks: ", res.Stocks)
	fmt.Println("\nUnvested amount: ", res.UnvestedAmount)

}
开发者ID:SindhujaNarra,项目名称:cmpe273-Assignment1,代码行数:26,代码来源:StockClient.go

示例11: rpcClient

func rpcClient() *rpc.Client {
	url, err := url.Parse(settings.RpcServerUrl)
	if err != nil {
		log.Fatal(err)
	}

	network := url.Scheme
	if network == "" {
		network = "unix"
	}

	var address string
	if network == "unix" {
		address = url.Path
	} else {
		address = url.Host
	}

	client, err := jsonrpc.Dial(network, address)
	if err != nil {
		log.Fatal(err)
	}

	return client
}
开发者ID:nangong92t,项目名称:go_src,代码行数:25,代码来源:main.go

示例12: main

func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage:", os.Args[0], "server")
		os.Exit(1)
	}
	serverAdd := os.Args[1]
	client, err := jsonrpc.Dial("tcp", serverAdd+":1234")

	if err != nil {
		log.Fatal("dialing:", err)
	}

	args := Args{17, 8}
	var reply int
	err = client.Call("Math.Multiply", args, &reply)

	if err != nil {
		log.Fatal("Math error:", err)
	}

	fmt.Printf("Math: %d*%d=%d\n", args.A, args.B, reply)

	var quo Quotient
	err = client.Call("Math.Divide", args, &quo)
	if err != nil {
		log.Fatal("Math error:", err)
	}

	fmt.Printf("Math: %d/%d=%d remainder %d\n", args.A, args.B, quo.Quo, quo.Rem)

}
开发者ID:pengswift,项目名称:go-test,代码行数:31,代码来源:client.go

示例13: WithRpcServer

func WithRpcServer(f func(c *rpc.Client)) error {
	file, err := ioutil.TempFile("", "gonit-rpc")
	if err != nil {
		return err
	}
	path := file.Name()
	defer os.Remove(path)
	os.Remove(path)

	url := "unix://" + path

	server, err := NewRpcServer(url)

	if err != nil {
		return err
	}

	go server.Serve()

	client, err := jsonrpc.Dial("unix", path)

	if err != nil {
		return err
	}

	defer client.Close()

	f(client)

	server.Shutdown()

	return nil
}
开发者ID:nangong92t,项目名称:go_src,代码行数:33,代码来源:helper.go

示例14: checkPortfolio

func checkPortfolio() {

	var TradeID int

	tradeID, _ := strconv.ParseInt(os.Args[1], 10, 32)
	TradeID = int(tradeID)

	client, err := jsonrpc.Dial("tcp", "localhost:1234")
	if err != nil {
		log.Fatal("dialing:", err)
	}

	var pfResponseObj PortfolioResponseObject

	err = client.Call("StockObject.CheckPortfolio", TradeID, &pfResponseObj)
	if err != nil {
		log.Fatal("Wrong Input", err)
	}

	fmt.Print("Stocks:")
	fmt.Println(pfResponseObj.Stocks)
	fmt.Print("Current Market Value:")
	fmt.Println(pfResponseObj.CurrentMarketValue)
	fmt.Print("Unvested Amount:")
	fmt.Println(pfResponseObj.UnvestedAmount)
}
开发者ID:HemanthSamayamantri,项目名称:CMPE273-Assignment1,代码行数:26,代码来源:StockCheckClient.go

示例15: buyStocks

func buyStocks() {

	var requestObject RequestObject

	requestObject.StockKey = os.Args[1]
	budget64, _ := strconv.ParseFloat(os.Args[2], 32)
	requestObject.Budget = float32(budget64)

	client, err := jsonrpc.Dial("tcp", "127.0.0.1:1234")
	if err != nil {
		log.Fatal("dialing:", err)
	}

	respObj := new(ResponseObject)

	err = client.Call("StockObject.ParseRequestObject", requestObject, &respObj)

	if err != nil {
		log.Fatal("Error thrown!", err)
	}

	fmt.Print("Result:")
	fmt.Println(respObj.Stocks)
	fmt.Print("TradeID:")
	fmt.Println(respObj.TradeID)
	fmt.Print("UnvestedAmount:")
	fmt.Println(respObj.UnvestedAmount)

}
开发者ID:HemanthSamayamantri,项目名称:CMPE273-Assignment1,代码行数:29,代码来源:StockCheckClient.go


注:本文中的net/rpc/jsonrpc.Dial函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。