|
|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2016, gRPC Authors All rights reserved.
|
|
|
+ * Copyright 2017, gRPC Authors All rights reserved.
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@@ -16,33 +16,11 @@
|
|
|
import Foundation
|
|
|
import Dispatch
|
|
|
import gRPC
|
|
|
+import Commander
|
|
|
|
|
|
let address = "localhost:8001"
|
|
|
let host = "foo.test.google.fr"
|
|
|
|
|
|
-func usage() {
|
|
|
- print("Usage: Simple <client|server>\n")
|
|
|
- exit(0)
|
|
|
-}
|
|
|
-
|
|
|
-func main() throws {
|
|
|
- gRPC.initialize()
|
|
|
- print("gRPC version", gRPC.version())
|
|
|
-
|
|
|
- print("\(CommandLine.arguments)")
|
|
|
- if CommandLine.arguments.count != 2 {
|
|
|
- usage()
|
|
|
- }
|
|
|
-
|
|
|
- let command = CommandLine.arguments[1]
|
|
|
- switch command {
|
|
|
- case "client": try client()
|
|
|
- case "server": try server()
|
|
|
- default:
|
|
|
- usage()
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func client() throws {
|
|
|
let message = "hello, server!".data(using: .utf8)
|
|
|
let c = gRPC.Channel(address:address, secure:false)
|
|
|
@@ -58,7 +36,6 @@ func client() throws {
|
|
|
["y": "yu"],
|
|
|
["z": "zither"]])
|
|
|
|
|
|
-
|
|
|
try! call.start(.unary, metadata:metadata, message:message) {
|
|
|
(response) in
|
|
|
print("status:", response.statusCode)
|
|
|
@@ -140,6 +117,20 @@ func server() throws {
|
|
|
_ = sem.wait(timeout: DispatchTime.distantFuture)
|
|
|
}
|
|
|
|
|
|
-try main()
|
|
|
+Group {
|
|
|
+
|
|
|
+ $0.command("server") {
|
|
|
+ gRPC.initialize()
|
|
|
+ print("gRPC version", gRPC.version())
|
|
|
+ try server()
|
|
|
+ }
|
|
|
+
|
|
|
+ $0.command("client") {
|
|
|
+ gRPC.initialize()
|
|
|
+ print("gRPC version", gRPC.version())
|
|
|
+ try client()
|
|
|
+ }
|
|
|
+
|
|
|
+ }.run()
|
|
|
|
|
|
|