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