netty的简单的应用例子
一、简单的聊天室程序
public class ChatClient {
public static void main(String[] args) throws InterruptedException, IOException {
NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup();
try{
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(nioEventLoopGroup).channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline()
// .addLast(new DelimiterBasedFrameDecoder(4096, Delimiters.lineDelimiter()))
.addLast(new LineBasedFrameDecoder(1024))
.addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8))
.addLast(new SimpleChannelInboundHandler<String>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
System.out.println(msg);
}
});
}
});
ChannelFuture future = bootstrap.connect("localhost", 8888).sync();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Channel channel = future.channel();
while(true){
channel.writeAndFlush(br.readLine()+"\n");
}
}finally{
nioEventLoopGroup.shutdownGracefully().sync();
}
}
}
public class ChatServer {
public static void main(String[] args) throws InterruptedException {
NioEventLoopGroup bossGroup = new NioEventLoopGroup();
NioEventLoopGroup workerGroup = new NioEventLoopGroup();
try{
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
// .addLast(new DelimiterBasedFrameDecoder(4096, Delimiters.lineDelimiter()))
.addLast(new LineBasedFrameDecoder(1024))
.addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8))
.addLast(new ChatServerHandler());
}
});
ChannelFuture future = serverBootstrap.bind(8888).sync();
future.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully().sync();
workerGroup.shutdownGracefully().sync();
}
}
}
public class ChatServerHandler extends SimpleChannelInboundHandler<String>{
public static final ChannelGroup group = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
Channel channel = ctx.channel();
group.forEach(ch ->{
if(channel != ch){
ch.writeAndFlush(channel.remoteAddress()+": "+ msg+"\n");
}else{
ch.writeAndFlush("自己: "+msg+"\n");
}
});
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
Channel channel = ctx.channel();
group.writeAndFlush("服务器: "+channel.remoteAddress()+"加入");
group.add(channel);
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
Channel channel = ctx.channel();
group.writeAndFlush("服务器 : "+channel.remoteAddress() + "离开");
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println(ctx.channel().remoteAddress()+" 上线");
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
System.out.println(ctx.channel().remoteAddress()+" 下线");
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
ctx.close();
}
}
二、使用netty传递对象,使用jdk自带的序列化
public class SubReqClient {
public static void main(String[] args) {
start();
}
public static void start(){
NioEventLoopGroup group = new NioEventLoopGroup();
try{
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioSocketChannel.class)
.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
.addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(
this.getClass().getClassLoader()
)))
.addLast("encoder", new ObjectEncoder())
.addLast(new SimpleChannelInboundHandler<Object>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println(msg);
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
User user = new User();
user.setName("runtu");
ctx.writeAndFlush(user);
}
});
}
});
ChannelFuture future = bootstrap.connect("localhost", 8888).sync();
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
group.shutdownGracefully();
}
}
}
public class SubReqServer {
public static void main(String[] args) {
start();
}
public static void start(){
NioEventLoopGroup bossGroup = new NioEventLoopGroup();
NioEventLoopGroup workGroup = new NioEventLoopGroup();
try{
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup,workGroup).channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
.addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(
this.getClass().getClassLoader()
)))
.addLast("encoder", new ObjectEncoder())
.addLast(new SimpleChannelInboundHandler<Object>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
User user1 = (User)msg;
System.out.println(user1.getName());
User user = new User();
user.setName("AQ");
ctx.writeAndFlush(user);
}
});
}
});
ChannelFuture future = serverBootstrap.bind(8888).sync();
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
}
public class User implements Serializable{
private String name;
private int age;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "User [name=" + name + ", age=" + age + ", address=" + address + "]";
}
}
三、使用messagepack进行序列化传递实体对象
由于java自带的序列化工具有着性能低、序列化后的码流大且不支持跨语言等各种缺陷,所以我们使用Msgpack库来进行序列化然后进行数据的传输。
我们需要额外引入两个jar包javassist-3.18.1-GA.jar 和msgpack-0.6.12.jar
public class NioClient {
public static void main(String[] args) throws InterruptedException {
NioEventLoopGroup group = new NioEventLoopGroup();
try{
Bootstrap bootStrap = new Bootstrap();
bootStrap.group(group).channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,3000)
.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
.addLast("frameDecoder",new LengthFieldBasedFrameDecoder(1024, 0, 2,0,2))
.addLast(new MsgpackDecoder())
.addLast("frameEncoder",new LengthFieldPrepender(2))
.addLast(new MsgpackEncoder())
.addLast(new ClientHandler());
}
});
ChannelFuture future = bootStrap.connect("localhost", 9999).sync();
future.channel().closeFuture().sync();
}finally{
group.shutdownGracefully();
}
}
}
public class ClientHandler extends SimpleChannelInboundHandler {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println(msg);
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
//发送50个UserInfo给服务器,由于启用了粘包/拆包支持,所以这里连续发送多个也不会出现粘包的现象。
for (int i = 0; i < 50; i++) {
User user = new User();
user.setName("张三"+i);
ctx.write(user);
}
ctx.flush();
System.out.println("-----------------send over-----------------");
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
System.out.println("error");
}
}
public class NioServer {
public static void main(String[] args) throws InterruptedException {
NioEventLoopGroup bossGroup = new NioEventLoopGroup();
NioEventLoopGroup workGroup = new NioEventLoopGroup();
try{
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workGroup).channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
.addLast("frameDecoder",new LengthFieldBasedFrameDecoder(1024, 0, 2,0,2))
.addLast(new MsgpackDecoder())
.addLast("frameEncoder",new LengthFieldPrepender(2))
.addLast(new MsgpackEncoder())
.addLast(new ServerHandler());
}
});
ChannelFuture future = serverBootstrap.bind(9999).sync();
future.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
}
public class ServerHandler extends SimpleChannelInboundHandler {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
//直接输出msg
System.out.println(msg.toString());
User user = new User();
user.setName("李四");
//回复has receive 给客户端
ctx.write(user);
} catch (Exception e) {
e.printStackTrace();
}finally {
}
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.flush();
}
}
public class MsgpackDecoder extends MessageToMessageDecoder<ByteBuf>{
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
final int length = buf.readableBytes();
final byte[] array = new byte[length];
buf.getBytes(buf.readerIndex(), array,0,length);
MessagePack messagePack = new MessagePack();
out.add(messagePack.read(array));
}
}
public class MsgpackEncoder extends MessageToByteEncoder<Object>{
@Override
protected void encode(ChannelHandlerContext ctx, Object obj, ByteBuf out) throws Exception {
MessagePack messagePack = new MessagePack();
byte[] info = messagePack.write(obj);
out.writeBytes(info);
}
}
@Message
public class User { private String name;
private int age;
private String address; public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
} @Override
public String toString() {
return "User [name=" + name + ", age=" + age + ", address=" + address + "]";
} }
四、使用Marshalling来对对象进行序列化,这种序列化方式需要对想实现Serializable接口
需要引入jar包 jboss-marshalling-2.0.6.Final.jar和jboss-marshalling-serial-2.0.6.Final.jar
public class SubReqClient {
public static void main(String[] args) {
start();
}
public static void start(){
NioEventLoopGroup group = new NioEventLoopGroup();
try{
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioSocketChannel.class)
.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder())
.addLast(MarshallingCodeCFactory.buildMarshallingEncoder())
.addLast(new SimpleChannelInboundHandler<Object>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println(msg);
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
User user = new User();
user.setName("runtu");
ctx.writeAndFlush(user);
}
});
}
});
ChannelFuture future = bootstrap.connect("localhost", 8888).sync();
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
group.shutdownGracefully();
}
}
}
public class SubReqServer {
public static void main(String[] args) {
start();
}
public static void start(){
NioEventLoopGroup bossGroup = new NioEventLoopGroup();
NioEventLoopGroup workGroup = new NioEventLoopGroup();
try{
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup,workGroup).channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder())
.addLast(MarshallingCodeCFactory.buildMarshallingEncoder())
.addLast(new SimpleChannelInboundHandler<Object>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
User user1 = (User)msg;
System.out.println(user1.getName());
User user = new User();
user.setName("AQ");
ctx.writeAndFlush(user);
}
});
}
});
ChannelFuture future = serverBootstrap.bind(8888).sync();
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
}
public class MarshallingCodeCFactory {
public static MarshallingDecoder buildMarshallingDecoder(){
final MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
DefaultUnmarshallerProvider provider = new DefaultUnmarshallerProvider(factory, configuration);
MarshallingDecoder decoder = new MarshallingDecoder(provider,1024);
return decoder;
}
public static MarshallingEncoder buildMarshallingEncoder(){
final MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
MarshallerProvider provider = new DefaultMarshallerProvider(factory, configuration);
MarshallingEncoder encoder = new MarshallingEncoder(provider);
return encoder;
}
}
public class User implements Serializable{
private String name;
private int age;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "User [name=" + name + ", age=" + age + ", address=" + address + "]";
}
}
五、简单的http文件服务器
public class HttpServer {
public static void main(String[] args) {
start();
}
public static void start(){
NioEventLoopGroup bossGroup = new NioEventLoopGroup();
NioEventLoopGroup workGroup = new NioEventLoopGroup();
try{
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup,workGroup).channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
.addLast(new HttpRequestDecoder())
.addLast(new HttpObjectAggregator(65535))
.addLast(new HttpResponseEncoder())
.addLast(new ChunkedWriteHandler())
.addLast(new FileServerHandler1());
}
});
ChannelFuture future = serverBootstrap.bind(8888).sync();
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
}
public class FileServerHandler1 extends SimpleChannelInboundHandler<FullHttpRequest>{
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
if(request.uri().equals("/favicon.ico")){
return;
}
if(request.method() == HttpMethod.GET){
String uri = request.uri();
if(uri.startsWith("/file")){
File file = new File("D:\\12306Bypass\\使用须知.txt");
RandomAccessFile randomAccessFile = null;
randomAccessFile = new RandomAccessFile(file, "r");
long fileLength = randomAccessFile.length();
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE)
.set("Content-Length", fileLength)
.set("Content-Type","text/html")
.set("Content-Disposition", "attachment;fileName="+"a.txt");
ctx.write(response);
ctx.write(new ChunkedFile(randomAccessFile, 0,fileLength,8192),ctx.newProgressivePromise());
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
}else{
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.headers()
.set("Content-Type", "text/plain;charset=utf-8")
.set("Content_Length", response.content().readableBytes())
.set("aaa", "cccc");
response.content().writeBytes(Unpooled.copiedBuffer("服务器返回信息",CharsetUtil.UTF_8));
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
}
}
private static void setContentTypeHeader(HttpResponse response, File file){
MimetypesFileTypeMap mimetypesFileTypeMap = new MimetypesFileTypeMap();
response.headers().set(HttpHeaderNames.CONTENT_TYPE, mimetypesFileTypeMap.getContentType(file.getPath()));
}
}
六、netty编写websocket服务器
public class WebSocketServer {
public static void main(String[] args) throws InterruptedException {
NioEventLoopGroup bossGroup = new NioEventLoopGroup();
NioEventLoopGroup workerGroup = new NioEventLoopGroup();
try{
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup,workerGroup).channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
.addLast(new HttpServerCodec())
.addLast(new HttpObjectAggregator(65536))
.addLast(new ChunkedWriteHandler())
.addLast(new WebSocketServerHandler());
}
});
ChannelFuture future = serverBootstrap.bind(8080).sync();
future.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully().sync();
workerGroup.shutdownGracefully().sync();
}
}
}
public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>{
private WebSocketServerHandshaker handshaker;
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
if(msg instanceof FullHttpRequest){
HandleHttpRequest(ctx,(FullHttpRequest)msg);
}
if(msg instanceof WebSocketFrame){
handleWebSocket(ctx,(WebSocketFrame)msg);
}
}
private void HandleHttpRequest(ChannelHandlerContext ctx,FullHttpRequest request){
WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(
"ws://localhost:8888/websocket",null,false);
handshaker = factory.newHandshaker(request);
if(handshaker == null){
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
}else{
handshaker.handshake(ctx.channel(),request);
}
}
private void handleWebSocket(ChannelHandlerContext ctx,WebSocketFrame frame){
if(frame instanceof CloseWebSocketFrame){
handshaker.close(ctx.channel(), (CloseWebSocketFrame)frame.retain());
}
if(frame instanceof PingWebSocketFrame){
ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
return;
}
if(!(frame instanceof TextWebSocketFrame)){
return;
}
String requestStr = ((TextWebSocketFrame) frame).text();
System.out.println(requestStr);
ctx.channel().writeAndFlush(new TextWebSocketFrame("欢迎使用netty websocket: "+ LocalDateTime.now()));
}
}
<html>
<head>
<meta charset="UTF-8">
Netty WebSocket服务器
<head>
<body>
<script type="text/javascript">
var socket;
if(!window.WebSocket){
window.WebSocket = window.MozWebSocket;
} if(window.WebSocket){
socket = new WebSocket("ws://localhost:8080/websocket");
socket.onmessage = function(event){
var ta = document.getElementById('responseText');
ta.value = '';
ta.value = event.data;
} socket.onopen = function(event){
var ta = document.getElementById('responseText');
ta.value = "打开WebSocket服务器正常";
} socket.onclose = function(event){
var ta = document.getElementById('responseText');
ta.value = "webSocket 关闭";
} } function send(){
if(socket.readyState == WebSocket.OPEN){
var message = document.getElementById('message').value;
socket.send(message);
}else{
alert("WebSocket 链接未建立成功!!");
}
}
</script>
<form onsubmit="return false;">
<input id="message" type="text" name = "message" value="Netty最佳实践"/> <br/><br/>
<input type="button" value="发送" onclick="send()"/>
<hr color="blue"/>
<h3>服务器应答消息</h3>
<textarea id="responseText" style="width:500px;height:300px;"></textarea>
</form> </body> </html>
netty的简单的应用例子的更多相关文章
- 一个简单的CORBA例子
因为对CORBA分析的需要,这里写一个简单的CORBA例子.从JDK1.2开始,JDK中集成了ORB的实现,本例子使用了JDK1.7,对于JDK1.2+应该都没有问题.这个例子实现一个简单的加减乘除的 ...
- 菜鸟学习Hibernate——简单的一个例子
一.Hibernate开发. 上篇博客已经为大家介绍了持久层框架的发展流程,持久层框架的种类. 为了能够使用Hibernate快速上手,我们先讲解一个简单的Hibernate应用实例hibernate ...
- 轻松创建nodejs服务器(1):一个简单nodejs服务器例子
这篇文章主要介绍了一个简单nodejs服务器例子,本文实现了一个简单的hello world例子,并展示如何运行这个服务器,需要的朋友可以参考下 我们先来实现一个简单的例子,hello world ...
- 使用Multiplayer Networking做一个简单的多人游戏例子-3/3(Unity3D开发之二十七)
使用Multiplayer Networking做一个简单的多人游戏例子-1/3 使用Multiplayer Networking做一个简单的多人游戏例子-2/3 使用Multiplayer Netw ...
- 使用Multiplayer Networking做一个简单的多人游戏例子-2/3(Unity3D开发之二十六)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/51007512 ...
- 使用Multiplayer Networking做一个简单的多人游戏例子-1/3(Unity3D开发之二十五)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/51006463 ...
- 一个简单的cmake例子
一个简单的cmake例子CMakeLists.txt,生成动态库文件,可以指定发布目录. 尚不支持: 1.交叉编译环境配置 2.添加依赖库 #在当前目录新建一个build目录,然后cd build ...
- vue双向数据绑定最最最最最简单直观的例子
vue双向数据绑定最最最最最简单直观的例子 一.总结 一句话总结:双向绑定既不仅model可以影响view的数据,view也可以影响model的数据 view model 数据 1.vue双向数据绑定 ...
- 一个最简单的JStorm例子
最简单的JStorm例子分为以下几个步骤: 1.生成Topology Map conf = new HashMp(); //topology所有自定义的配置均放入这个Map TopologyBuild ...
随机推荐
- typescript中类的继承
typescript中类的继承用到的是:extends和super 先看一下typescript中类的写法: class Demo{ //类的属性 name:string; age:number; / ...
- Puppeteer学习之小试牛刀
最近有了写文章的动力了,一方面是受到了很多前辈们的启示,另一方面也是为了记录下来更好地学以致用.闲言少叙,先说说Puppeteer是什么. Puppeteer是一个node库,提供了一些用来操作Chr ...
- 该用Python还是SQL?4个案例教你节省时间
在数据分析行业,对数据提出的每一个问题都可以用多种潜在的语言和工具包来回答.每种语言都有其优势,它们之间也存在着不同的区别.不能否认的是,有些操作用Python执行起来要比SQL更加高效.这篇文章分享 ...
- Redis笔记-Sentinel哨兵模式
Redis以主从的模式搭建集群后,如果主节点Master挂掉,虽然可以实现将备用节点Slave切换成主节点,但是Redis本身并没有自动监控机制,需要借助Sentinel哨兵模式,实现监控并实现自动切 ...
- SQL Server数据库————模糊查询和聚合函数
***********模糊查询*********/ 关键字: like (!!!!字符串类型) in (,,) 匹配()内的某个具体值(括号里可以写多个值) between... and.. 在某两 ...
- dicom错误解决
https://github.com/pydicom/pydicom/issues/331 sudo apt-get install python-gdcm
- input type=file的几个属性
<input type='file' /> inputDom.onchange=function (e){ e.currentTarget.files 是只有一个对象的数组 var ob ...
- ginput函数用法
1.ginput函数:获取指定点坐标值 2.用法说明 (1)[x,y] = ginput(n) 函数从当前的坐标轴上选择n个点,并返回这n个点相应的坐标值(x,y).这n个点可由鼠标定位.用户可以按下 ...
- 播放器授权后播放内容时出现Cnario logo水印
问题描述 Player获取License后, 通过Messeenger发布到Player的内容前面出现Cnario 的logo水印, 如下图样式: 原因 出现这种情况一般是由于License授权不正确 ...
- [蓝桥杯]2017蓝桥省赛B组题目及详解
/*——————————————————————————————————————————————————————————— [结果填空题]T1 (分值:5) 题目:购物单 小明刚刚找到工作,老板人很好 ...