TCP粘包/拆包

TCP是个”流”协议,所谓流,就是没有界限的一串数据。TCP底层并不了解上层业务数据的具体含义,它会根据TCP缓冲区的实际情况进行包的划分,所以在业务上认为,一个完整的包可能会被TCP拆分成多个包进行发送,也有可能把多个小的包封装成一个大的数据包发送,这就是所谓的TCP粘包和拆包问题

TCP粘包/拆包发生的原因

1. 应用程序write写入的字节大小大于套接口发送缓冲区大小
2. 进行MSS大小的TCP分段
3. 以太网帧的payload大于MTU进行IP分片

粘包问题的解决策略

由于底层的TCP无法理解上层的业务数据,所以在底层是无法保证数据包不被拆分和重组的,这个问题只能通过上层的应用协议栈设计来解决,根据业界的主流协议的解决方案,可以归纳如下

先来看一个粘包的例子

新建maven工程,添加依赖包

<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>5.0..Alpha1</version>
</dependency>

TimeServer

package com.zhen.netty1129_TCP_HALF_PACKAGE;

import java.awt.Event;
import java.net.Socket; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel; public class TimeServer { public void bind(int port) throws Exception{
//配置服务端的NIO线程组
//NioEventLoopGroup是个线程组,它包含了一组NIO线程,专门用于网络事件的处理,实际上它们就是Reactor线程组
//bossGroup用于服务端接受客户端的连接
EventLoopGroup bossGroup = new NioEventLoopGroup();
//workerGroup进行SocketChannel的网络读写
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
//Netty用于启动NIO服务端的辅助启动类,目的是降低服务端的开发复杂度
ServerBootstrap bootstrap = new ServerBootstrap();
//将两个NIO线程组当作入参传递到ServerBootstrap
bootstrap.group(bossGroup, workerGroup)
//设置创建的Channel为NioServerSocketChannel,它的功能对应于JDK NIO类库中的ServerSocketChannel类。
.channel(NioServerSocketChannel.class)
//配置NioServerSocketChannel的TCP参数,此处将它的backlog设置为1024
.option(ChannelOption.SO_BACKLOG, )
//绑定I/O事件的处理类ChildChannelHandler,它的作用类似于Reactor模式中的Handler类,主要用于处理网络I/O事件,例如记录日志、对消息进行编解码等
.childHandler(new ChildChannelHandler());
//调用bind方法绑定监听端口,随后,调用它的同步阻塞方法sync等待绑定操作完成。
//完成之后Netty会返回一个ChannelFuture,它的功能类似于JDK的java.util.concurrent.Future,主要用于异步操作的通知回调
ChannelFuture future = bootstrap.bind(port).sync();
//等待服务端监听端口关闭,等待服务端链路关闭之后main函数才退出
future.channel().closeFuture().sync();
} finally {
//优雅退出,释放线程池资源
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
} private class ChildChannelHandler extends ChannelInitializer<SocketChannel>{
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new TimeServerHandler());
}
} public static void main(String[] args) throws Exception {
int port = ;
if (args != null && args.length > ) {
try {
port = Integer.valueOf(args[]);
} catch (Exception e) {
e.printStackTrace();
}
}
new TimeServer().bind(port);
}
}

TimeServerHandler

package com.zhen.netty1129_TCP_HALF_PACKAGE;

import java.util.Date;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; //TimeServerHandler 继承自ChannelHandlerAdapter,它用于对网络事件进行读写操作
public class TimeServerHandler extends ChannelHandlerAdapter{ private int counter; @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//将msg转换成Netty的ByteBuf对象。ByteBuf类似于jdk中的java.nio.ByteBuffer对象,不过它提供了更加强大和灵活的功能
ByteBuf buf = (ByteBuf) msg;
//通过ByteBuf的readableBytes方法可以获取缓冲区可读的字节数,根据可读的字节数创建byte数组
byte[] req = new byte[buf.readableBytes()];
//通过ByteBuf的readBytes方法将缓冲区中的字节数据复制到新建的byte数组中
buf.readBytes(req);
//通过new String构造函数获取请求消息
String body = new String(req, "UTF-8").substring(, req.length
- System.getProperty("line.separator").length());
System.out.println("The time server receive order : " + body
+ "; the counter is : "+ ++counter);
//对请求消息进行判断,如果是QUERY TIME ORDER则创建应答消息
String currentTime = "QUERY TIME ORDER".equalsIgnoreCase(body) ?
new Date(System.currentTimeMillis()).toString() : "BAD ORDER";
currentTime = currentTime + System.getProperty("line.separator");
ByteBuf resp = Unpooled.copiedBuffer(currentTime.getBytes());
//通过ChannelHandlerContext的write方法异步发送应答消息给客户端
ctx.writeAndFlush(resp);
} @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
//当发生异常时,关闭ChannelHandlerContext,释放和ChannelHandlerContext相关联的句柄等资源
ctx.close();
}
}

TimeClient

package com.zhen.netty1129_TCP_HALF_PACKAGE;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel; public class TimeClient { public void connect(int port,String host) throws Exception{
//配置客户端NIO线程组,客户端处理I/O读写的NioEventLoopGroup线程组
EventLoopGroup group = new NioEventLoopGroup();
try {
//客户端辅助启动类Bootstrap
Bootstrap bootstrap = new Bootstrap();
//设置线程组
bootstrap.group(group)
//与服务端不同的是,它的channel需要设置为NioSocketChannel
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
//然后为其添加Handler,此处为了简单直接创建匿名内部类,实现initChannel方法
//作用是当创建NioSocketChannel成功之后,在进行初始化时,将它的ChannelHandler设置到ChannelPipeline中,用于处理网络I/O事件
.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(new TimeClientHandler());
}
});
//调用connect发起异步连接操作,然后调用sync同步方法等待连接成功。
ChannelFuture future = bootstrap.connect(host, port).sync();
//等待客户端链路关闭,当客户端连接关闭之后,客户端主函数退出,退出之前释放NIO线程组的资源
future.channel().closeFuture().sync();
} finally {
//优雅退出,释放NIO线程组
group.shutdownGracefully();
}
} public static void main(String[] args) throws Exception{
int port = ;
String host = "127.0.0.1";
if (args != null && args.length > ) {
try {
port = Integer.valueOf(args[]);
} catch (Exception e) {
e.printStackTrace();
}
}
new TimeClient().connect(port, host);
} }

TimeClientHandler

package com.zhen.netty1129_TCP_HALF_PACKAGE;

import java.util.logging.Logger;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; public class TimeClientHandler extends ChannelHandlerAdapter{ private static final Logger logger = Logger.getLogger(TimeClientHandler.class.getName()); private int counter; private byte[] req; public TimeClientHandler(){
req = ("QUERY TIME ORDER"+System.getProperty("line.separator")).getBytes(); } //当客户端和服务端TCP链路建立成功之后,Netty的NIO线程会调用channelActive方法,发送查询时间的指令给服务端
//调用ChannelHandlerContext的writeAndFlush方法将请求消息发送给客户端
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ByteBuf message = null;
for (int i = ; i < ; i++) {
message = Unpooled.buffer(req.length);
message.writeBytes(req);
ctx.writeAndFlush(message);
}
} //当客户端返回应答消息,channelRead方法被调用
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
byte[] req = new byte[buf.readableBytes()];
buf.readBytes(req);
String body = new String(req, "UTF-8");
System.out.println("Now is :" + body + " ; the counter is : " + ++counter);
} //发生异常时,释放客户端资源
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.warning("Unexpected exception from downstream : " + cause.getMessage());
ctx.close();
} }

此时启动server,再启动client,可看到以下结果

server端

client端

可以发现,server只受到了两条消息,说明发生了粘包,但是我们期望的是收到100条消息,每条包含一条”QUERY TIME ORDER”指令,这说明发生了TCP粘包
客户端应该收到100条当前系统时间,但实际上只收到了一条,因为服务端只收到了2条请求消息,所以实际服务端只发送了2条应答,由于请求消息不满足查询条件,所以返回了2条”BAD ORDER”应答消息。但是实际上客户端只收到了一条包含两条”BAD ORDER”指令的消息,说明服务端返回的应答消息也发生了粘包

解决TCP粘包问题

利用LineBasedFrameDecoder解决TCP粘包问题

为了解决TCP粘包/拆包导致的半包读写问题,Netty默认提供了多种编解码器用于处理半包,只要能熟练掌握这些类库的使用,TCP粘包问题从此会变得非常容易

来看代码

TimeServer

package com.zhen.netty1129_TCP_HALF_PACKAGE_SOLVE;

import java.awt.Event;
import java.net.Socket; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder; public class TimeServer { public void bind(int port) throws Exception{
//配置服务端的NIO线程组
//NioEventLoopGroup是个线程组,它包含了一组NIO线程,专门用于网络事件的处理,实际上它们就是Reactor线程组
//bossGroup用于服务端接受客户端的连接
EventLoopGroup bossGroup = new NioEventLoopGroup();
//workerGroup进行SocketChannel的网络读写
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
//Netty用于启动NIO服务端的辅助启动类,目的是降低服务端的开发复杂度
ServerBootstrap bootstrap = new ServerBootstrap();
//将两个NIO线程组当作入参传递到ServerBootstrap
bootstrap.group(bossGroup, workerGroup)
//设置创建的Channel为NioServerSocketChannel,它的功能对应于JDK NIO类库中的ServerSocketChannel类。
.channel(NioServerSocketChannel.class)
//配置NioServerSocketChannel的TCP参数,此处将它的backlog设置为1024
.option(ChannelOption.SO_BACKLOG, )
//绑定I/O事件的处理类ChildChannelHandler,它的作用类似于Reactor模式中的Handler类,主要用于处理网络I/O事件,例如记录日志、对消息进行编解码等
.childHandler(new ChildChannelHandler());
//调用bind方法绑定监听端口,随后,调用它的同步阻塞方法sync等待绑定操作完成。
//完成之后Netty会返回一个ChannelFuture,它的功能类似于JDK的java.util.concurrent.Future,主要用于异步操作的通知回调
ChannelFuture future = bootstrap.bind(port).sync();
//等待服务端监听端口关闭,等待服务端链路关闭之后main函数才退出
future.channel().closeFuture().sync();
} finally {
//优雅退出,释放线程池资源
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
} private class ChildChannelHandler extends ChannelInitializer<SocketChannel>{
@Override
protected void initChannel(SocketChannel ch) throws Exception {
//在原来的TimeServerHandler之前新增了两个解码器LineBasedFrameDecoder、StringDecoder
ch.pipeline().addLast(new LineBasedFrameDecoder(1024));
ch.pipeline().addLast(new StringDecoder());
ch.pipeline().addLast(new TimeServerHandler());
}
} public static void main(String[] args) throws Exception {
int port = ;
if (args != null && args.length > ) {
try {
port = Integer.valueOf(args[]);
} catch (Exception e) {
e.printStackTrace();
}
}
new TimeServer().bind(port);
}
}

TimeServerHandler

package com.zhen.netty1129_TCP_HALF_PACKAGE_SOLVE;

import java.util.Date;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; //TimeServerHandler 继承自ChannelHandlerAdapter,它用于对网络事件进行读写操作
public class TimeServerHandler extends ChannelHandlerAdapter{ private int counter; @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
String body = (String)msg;
System.out.println("The time server receive order : " + body
+ "; the counter is : "+ ++counter);
//对请求消息进行判断,如果是QUERY TIME ORDER则创建应答消息
String currentTime = "QUERY TIME ORDER".equalsIgnoreCase(body) ?
new Date(System.currentTimeMillis()).toString() : "BAD ORDER";
currentTime = currentTime + System.getProperty("line.separator");
ByteBuf resp = Unpooled.copiedBuffer(currentTime.getBytes());
//通过ChannelHandlerContext的write方法异步发送应答消息给客户端
ctx.writeAndFlush(resp);
} @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
//当发生异常时,关闭ChannelHandlerContext,释放和ChannelHandlerContext相关联的句柄等资源
ctx.close();
}
}

TimeClient

package com.zhen.netty1129_TCP_HALF_PACKAGE_SOLVE;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder; public class TimeClient { public void connect(int port,String host) throws Exception{
//配置客户端NIO线程组,客户端处理I/O读写的NioEventLoopGroup线程组
EventLoopGroup group = new NioEventLoopGroup();
try {
//客户端辅助启动类Bootstrap
Bootstrap bootstrap = new Bootstrap();
//设置线程组
bootstrap.group(group)
//与服务端不同的是,它的channel需要设置为NioSocketChannel
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
//然后为其添加Handler,此处为了简单直接创建匿名内部类,实现initChannel方法
//作用是当创建NioSocketChannel成功之后,在进行初始化时,将它的ChannelHandler设置到ChannelPipeline中,用于处理网络I/O事件
.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
//在原来的TimeClientHandler之前新增了两个解码器LineBasedFrameDecoder、StringDecoder
ch.pipeline().addLast(new LineBasedFrameDecoder(1024));
ch.pipeline().addLast(new StringDecoder());
ch.pipeline().addLast(new TimeClientHandler());
}
});
//调用connect发起异步连接操作,然后调用sync同步方法等待连接成功。
ChannelFuture future = bootstrap.connect(host, port).sync();
//等待客户端链路关闭,当客户端连接关闭之后,客户端主函数退出,退出之前释放NIO线程组的资源
future.channel().closeFuture().sync();
} finally {
//优雅退出,释放NIO线程组
group.shutdownGracefully();
}
} public static void main(String[] args) throws Exception{
int port = ;
String host = "127.0.0.1";
if (args != null && args.length > ) {
try {
port = Integer.valueOf(args[]);
} catch (Exception e) {
e.printStackTrace();
}
}
new TimeClient().connect(port, host);
} }

TimeClientHandler

package com.zhen.netty1129_TCP_HALF_PACKAGE_SOLVE;

import java.util.logging.Logger;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; public class TimeClientHandler extends ChannelHandlerAdapter{ private static final Logger logger = Logger.getLogger(TimeClientHandler.class.getName()); private int counter; private byte[] req; public TimeClientHandler(){
req = ("QUERY TIME ORDER"+System.getProperty("line.separator")).getBytes(); } //当客户端和服务端TCP链路建立成功之后,Netty的NIO线程会调用channelActive方法,发送查询时间的指令给服务端
//调用ChannelHandlerContext的writeAndFlush方法将请求消息发送给客户端
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ByteBuf message = null;
for (int i = ; i < ; i++) {
message = Unpooled.buffer(req.length);
message.writeBytes(req);
ctx.writeAndFlush(message);
}
} //当客户端返回应答消息,channelRead方法被调用
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//拿到的msg已经是解码成字符串之后的应答消息了。
String body = (String)msg;
System.out.println("Now is :" + body + " ; the counter is : " + ++counter);
} //发生异常时,释放客户端资源
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.warning("Unexpected exception from downstream : " + cause.getMessage());
ctx.close();
} }

此时再次运行,查看结果

Server端

client端

此时TCP粘包问题已经解决

LineBasedFrameDecoder和StringDecoder的原理分析
LineBasedFrameDecoder的工作原理是依次便利ByteBuf中的刻度子节,判断看是否有”\n” 或者“\r”,如果有,就以此为止为结束位置,从可读索引到结束位置区间的字节久组成了一行。它是以换行符为结束标志的解码器,支持携带结束符或者不携带结束符两种编码方式,同时支持配置单行的最大长度后仍然没有发现换行符,就会抛出异常,同时忽略掉之前读到的异常码流。
StringDecoder的功能非常简单,就是将接收到的对象转换成字符串,然后继续调用后面的handler。LineBasedFrameDecoder+StringDecoder组合就是按行切换的文本解码器,它被设计用来支持TCP的粘包和拆包.

Netty使用LineBasedFrameDecoder解决TCP粘包/拆包的更多相关文章

  1. 深入学习Netty(5)——Netty是如何解决TCP粘包/拆包问题的?

    前言 学习Netty避免不了要去了解TCP粘包/拆包问题,熟悉各个编解码器是如何解决TCP粘包/拆包问题的,同时需要知道TCP粘包/拆包问题是怎么产生的. 在此博文前,可以先学习了解前几篇博文: 深入 ...

  2. Netty(三)TCP粘包拆包处理

    tcp是一个“流”的协议,一个完整的包可能会被TCP拆分成多个包进行发送,也可能把小的封装成一个大的数据包发送,这就是所谓的TCP粘包和拆包问题. 粘包.拆包问题说明 假设客户端分别发送数据包D1和D ...

  3. Netty(二)——TCP粘包/拆包

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7814644.html 前面讲到:Netty(一)--Netty入门程序 主要内容: TCP粘包/拆包的基础知 ...

  4. 《精通并发与Netty》学习笔记(13 - 解决TCP粘包拆包(一)概念及实例演示)

    一.粘包/拆包概念 TCP是一个“流”协议,所谓流,就是没有界限的一长串二进制数据.TCP作为传输层协议并不不了解上层业务数据的具体含义,它会根据TCP缓冲区的实际情况进行数据包的划分,所以在业务上认 ...

  5. 1. Netty解决Tcp粘包拆包

    一. TCP粘包问题 实际发送的消息, 可能会被TCP拆分成很多数据包发送, 也可能把很多消息组合成一个数据包发送 粘包拆包发生的原因 (1) 应用程序一次写的字节大小超过socket发送缓冲区大小 ...

  6. 【转】Netty之解决TCP粘包拆包(自定义协议)

    1.什么是粘包/拆包 一般所谓的TCP粘包是在一次接收数据不能完全地体现一个完整的消息数据.TCP通讯为何存在粘包呢?主要原因是TCP是以流的方式来处理数据,再加上网络上MTU的往往小于在应用处理的消 ...

  7. Netty之解决TCP粘包拆包(自定义协议)

    1.什么是粘包/拆包 一般所谓的TCP粘包是在一次接收数据不能完全地体现一个完整的消息数据.TCP通讯为何存在粘包呢?主要原因是TCP是以流的方式来处理数据,再加上网络上MTU的往往小于在应用处理的消 ...

  8. 《精通并发与Netty》学习笔记(14 - 解决TCP粘包拆包(二)Netty自定义协议解决粘包拆包)

    一.Netty粘包和拆包解决方案 Netty提供了多个解码器,可以进行分包的操作,分别是: * LineBasedFrameDecoder (换行)   LineBasedFrameDecoder是回 ...

  9. Netty解决TCP粘包/拆包问题 - 按行分隔字符串解码器

    服务端 package org.zln.netty.five.timer; import io.netty.bootstrap.ServerBootstrap; import io.netty.cha ...

随机推荐

  1. 自己定义控件三部曲视图篇(二)——FlowLayout自适应容器实现

    前言:我最大的梦想,就是有一天.等老了坐在摇椅上回望一生,有故事给孩子们讲--. 相关文章: <Android自己定义控件三部曲文章索引>:http://blog.csdn.net/har ...

  2. centos6下手工编译vitess

    vitess是youtub开源的一款mysql代理,在ubuntu下编译非常方便.可是在centos下且不能訪问google的情况下坑比較多.近期依据其bootstrap.sh脚本手工编译成功.把过程 ...

  3. HDFS源码分析数据块复制监控线程ReplicationMonitor(二)

    HDFS源码分析数据块复制监控线程ReplicationMonitor(二)

  4. Web性能测试工具:http_load安装&使用简介

    除了siege,在Web性能测试工具中,http_load也是比较热门和常见的一款,有时因为种种原因,只能使用现成的工具,所以多了解和掌握一种Web性能测试工具是很有必要的. 1.下载安装包 略过 2 ...

  5. 微服务网关哪家强?一文看懂Zuul, Nginx, Spring Cloud, Linkerd性能差异

      导语:API Gateway是实现微服务重要的组件之一.面对诸多的开源API Gateway,如何进行选择也是架构师需要关注的焦点.本文作者对几个较大的开源API Gateway进行了压力测试,对 ...

  6. mysql 与mongodb的特点与优劣

    首先我们来分析下mysql 与mongodb的特点与优劣.下面是我以前做的ppt的部分截图. 再来分析下应用场景,a.如果需要将mongodb作为后端db来代替mysql使用,即这里mysql与mon ...

  7. Java多线程之~~~~synchronized 方法

    在多线程开发中,总会遇到多个在不同线程中的方法操作同一个数据,这样在不同线程中操作这个数据不同的顺序 或者时机会导致各种不同的现象发生,以至于不能实现你预期的效果,不能实现一致性,这时候就能够使用 s ...

  8. unity shader 编辑器扩展类 ShaderGUI

    这应该unity5才出的新功能了,今天看文档时刚巧看到了,就来尝试了一下. 效果如图: shader 的编辑器扩展分为2种方法: 是通过UnityEditor下的ShaderGUI类来实现的,形式比较 ...

  9. Google Gson实现JSON字符串和对象之间相互转换

    User实体类 package com.test.json; /** * User 实体类 */ public class User { private String name; private St ...

  10. easyui首页模板

    Easyui首页html代码 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "htt ...