Since Netty can't be used in Android, how it should be done in an Android Client? I couldn't find any useful example.
On Thursday, January 14, 2016 at 1:43:32 PM UTC+5:30, Young You wrote: > > It works! Thank you very much! > > 在 2016年1月14日星期四 UTC+8上午3:44:41,Eric Anderson写道: >> >> Yep, you need to use GrpcSslContexts >> <http://www.grpc.io/grpc-java/javadoc/io/grpc/netty/GrpcSslContexts.html> >> : >> GrpcSslContexts.forClient().trustManager(...).build(); >> GrpcSslContexts.forServer(new File...).build(); >> >> Alternatively, you could use GrpcSslContexts.configure(...), but I'd >> suggest the easier forms above. >> >> On Wed, Jan 13, 2016 at 1:35 AM, Young You <youngy...@gmail.com> wrote: >> >>> // Server >>> >>> SslContext sslContext = SslContextBuilder.forServer( >>> new File("/Users/u/Desktop/api.grpc/src/main/resources/server.crt"), >>> new >>> File("/Users/u/Desktop/api.grpc/src/main/resources/private_key_pkcs8.pem")) >>> .build(); >>> >>> server = NettyServerBuilder.forPort(port).sslContext(sslContext) >>> .addService(GreeterGrpc.bindService(new GreeterImpl())).build() >>> .start(); >>> >>> >>> // Client >>> SslContext sslContext = SslContextBuilder.forClient().trustManager(new File( >>> >>> "/Users/u/Desktop/api.grpc/src/main/resources/server.crt")).build(); >>> channel = NettyChannelBuilder.forAddress(host, port) >>> .sslContext(sslContext) >>> .build(); >>> blockingStub = GreeterGrpc.newBlockingStub(channel); >>> >>> >>> Both server and client do not work, I have tried with another client and >>> server written in Ruby. >>> >>> >>> 在 2016年1月8日星期五 UTC+8上午11:10:59,Young You写道: >>> >>>> Can someone give me an example with grpc-java and ssl ? >>>> >>>> My code returns this error >>>> >>>> io.grpc.StatusRuntimeException: UNKNOWN >>>> at io.grpc.Status.asRuntimeException(Status.java:430) >>>> at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:156) >>>> at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:106) >>>> at >>>> ex.grpc.GreeterGrpc$GreeterBlockingStub.sayHello(GreeterGrpc.java:109) >>>> at >>>> com.chinark.api.helloworld.HelloWorldClient.greet(HelloWorldClient.java:45) >>>> at >>>> com.chinark.api.helloworld.HelloWorldClient.main(HelloWorldClient.java:60) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>> at >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) >>>> at >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >>>> at java.lang.reflect.Method.invoke(Method.java:497) >>>> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) >>>> Caused by: java.lang.Exception: Failed ALPN negotiation: Unable to find >>>> compatible protocol. >>>> at >>>> io.grpc.netty.ProtocolNegotiators$BufferUntilTlsNegotiatedHandler.userEventTriggered(ProtocolNegotiators.java:400) >>>> at >>>> io.netty.channel.ChannelHandlerInvokerUtil.invokeUserEventTriggeredNow(ChannelHandlerInvokerUtil.java:75) >>>> at >>>> io.netty.channel.DefaultChannelHandlerInvoker.invokeUserEventTriggered(DefaultChannelHandlerInvoker.java:135) >>>> at >>>> io.netty.channel.AbstractChannelHandlerContext.fireUserEventTriggered(AbstractChannelHandlerContext.java:149) >>>> at >>>> io.netty.channel.ChannelInboundHandlerAdapter.userEventTriggered(ChannelInboundHandlerAdapter.java:108) >>>> at >>>> io.netty.channel.ChannelHandlerInvokerUtil.invokeUserEventTriggeredNow(ChannelHandlerInvokerUtil.java:75) >>>> at >>>> io.netty.channel.DefaultChannelHandlerInvoker.invokeUserEventTriggered(DefaultChannelHandlerInvoker.java:135) >>>> at >>>> io.netty.channel.AbstractChannelHandlerContext.fireUserEventTriggered(AbstractChannelHandlerContext.java:149) >>>> at >>>> io.netty.handler.ssl.SslHandler.setHandshakeSuccess(SslHandler.java:1240) >>>> at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1067) >>>> at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:965) >>>> at >>>> io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:327) >>>> at >>>> io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:230) >>>> at >>>> io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:83) >>>> at >>>> io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelRead(DefaultChannelHandlerInvoker.java:153) >>>> at >>>> io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:157) >>>> at >>>> io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:946) >>>> at >>>> io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125) >>>> at >>>> io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:510) >>>> at >>>> io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:467) >>>> at >>>> io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:381) >>>> at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) >>>> at >>>> io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742) >>>> at >>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) >>>> at >>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) >>>> at java.lang.Thread.run(Thread.java:745) >>>> >>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "grpc.io" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to grpc-io+u...@googlegroups.com. >>> To post to this group, send email to grp...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/grpc-io/36e418b7-7298-4f3e-ae4f-6fed3fd8052c%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/grpc-io/36e418b7-7298-4f3e-ae4f-6fed3fd8052c%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscr...@googlegroups.com. To post to this group, send email to grpc-io@googlegroups.com. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/abc7de2a-e4f1-4bf2-a693-1d193f9163cd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.