好吧,今天继续简略的记录一下。记记几周之前写的一小段代码,关于在Netty中同时使用SSL和Google Protobuf的配置。
首先是Netty的initChannel相关代码:
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
// SSL相关,可以参考netty example中的io.netty.example.securechat.*的代码
p.addLast("ssl", new SslHandler(YourServerSslContextFactory.createSSLEngine()));
// Protobuf相关,可以参考netty example中的io.netty.example.worldclock.*的代码
ExtensionRegistry registry = ExtensionRegistry.newInstance();
YourProtobufClass.registerAllExtensions(registry);
p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
p.addLast("protobufDecoder", new ProtobufDecoder(YourProtobufClass.YourClass.getDefaultInstance(), registry));
p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
p.addLast("protobufEncoder", new ProtobufEncoder());
p.addLast(new LoggingHandler(LogLevel.INFO));
p.addLast(handler);
}
顺便提提用java的keytool来生成SSL证书的命令:
keytool -genkey -alias YOUR_KEY_NAME -keysize 2048 -validity 365 -keyalg RSA -dname "CN=127.0.0.1,OU=YOUR_KEY_NAME" -keypass YOUR_KEY_PASSWORD -storepass changeit -keystore YOUR_FILE_NAME.jks
这里的-storepass changeit,因为jdk默认的密码是changeit,我的jdk没做过修改,还是默认的。
上面有很多YourClassXX或YOUR_XX之类的,表示需要根据自己的情况来做修改的~
发布在:http://auzll.iteye.com
分享到:
相关推荐
1、基于netty+websocket+springboot的实时聊天系统项目源码.zip 2、该资源包括项目的全部源码,下载可以直接使用! 3、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料...
springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot...
来自于疯狂创客圈 《netty+protobuf 整合实战》的源代码,付上了 protobuf 的 protoc 工具, protoc-2.6.1-win32.zip
springboot+netty+websocket+redis 分布式聊天,实现简单的聊天功能
java netty 服务端 + unity客户端 +protobuf3 实现网游通讯demo
cdeer-im, 基于Netty+Redis+protobuf开发的即时通讯服务器
基于Netty+TCP+Protobuf实现的Android IM库,包含Protobuf序列化、TCP拆包与粘包、长连接握手认证、心跳机制、断线重连机制、消息重发机制、读写超时机制、离线消息、线程池等功能
基于springboot+netty+vue构建的类似bililbili的弹幕群聊系统,个人娱乐项目,可用于前后端开发学习研究 基于springboot+netty+vue构建的类似bililbili的弹幕群聊系统,个人娱乐项目,可用于前后端开发学习研究 ...
Netty+Spring Boot仿微信 全栈开发高性能后台及客户端
毕设项目:基于netty+websocket+springboot的实时聊天系统 毕设项目:基于netty+websocket+springboot的实时聊天系统 毕设项目:基于netty+websocket+springboot的实时聊天系统 毕设项目:基于netty+websocket+...
绍如何搭建一个准实时聊天问答程序,包括微信小程序和H5网页版。...该项目服务端主要使用了Java + Spring Boot + Netty + WebSocket等技术栈,聊天客户端使用的是UniApp来轻松搭建微信小程序和H5网页端。
netty案例,netty4.1中级拓展篇六《SpringBoot+Netty+Elasticsearch收集日志信息数据存储》源码 ...
基于springcloud+Netty+MQ+mysql的分布式即时聊天系统.zip基于springcloud+Netty+MQ+mysql的分布式即时聊天系统.zip基于springcloud+Netty+MQ+mysql的分布式即时聊天系统.zip基于springcloud+Netty+MQ+mysql的分布式...
omen-1.1 自己基于netty开发的服务端,支持spring配置服务器启动模式:http,tcp,websocket等,并支持NIO和OIO方式,项目已应用于生产,可以通过jar形式加入其它项目,业务类实现业务service,启动不依赖于其他应用...
通过学习netty + protobuf 开发小项聊天程序的例子,可以掌握 netty 的开发 和 协议栈的设计等
netty+4G DTU
Spring+Netty+WebSocket实例,通用性还行,比较贴近生产,注释什么写的比较全
springboot+netty+mybatis+sqlserver,socket,整合sqlserver2014和bean的注入问题,springboot的异步加载bean