既然已经写完了相关的服务器处理类,那么我们就来搭建客户端测试一下。

打开我们的unity3d,然后新建一个c#脚本,取名为MainClient。

public class MainClient : MonoBehaviour{
private const string HOST = "127.0.0.1";
private const int PORT = 8080;
public static MainClient instance;
public static TcpClient client;
void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this.gameObject);
}
}
void Start()
{
if (client == null)
{
Connect();
}
}
void Update()
{
}
void OnApplicationQuit()
{
client.Close();
}
public void Connect()
{
client = new TcpClient();
try{
client.Connect(HOST,PORT);
}catch(Exception e){
Debug.LogException(e);
client.Close();
}
} }

  然后再Hierarchy窗口新建一个gameobject,将MainClient赋给它,将之做成prefab。

好了,我们先启动服务器,再启动我们的unity3d工程,会发现呢

服务器会跳转到之前我们写的处理类ServerHandler的方法,public void channelActive(ChannelHandlerContext ctx),打印这句话,channel.id()就是唯一标识该客户端,感兴趣的童鞋可以去学习netty的源代码。

当我们断开unity3d客户端,就会调用public void channelInactive(ChannelHandlerContext ctx)

好了测试相关的已经成功了,如果有什么问题可以留言给我,这个是我服务器写到一定程度才写这篇博文的,可能有步骤不对,你们尽管指出来。

最新文章

  1. WinCE项目应用之车载导航
  2. 【Alpha版本】冲刺-Day7
  3. top命令详解(转,详细)
  4. libtool: link: `dftables.lo' is not a valid libtool object
  5. Java中只有按值传递,没有按引用传递!
  6. 最小K个数之和
  7. ZOJ3732 Graph Reconstruction Havel-Hakimi定理
  8. sql server语句
  9. cf B. Levko and Permutation
  10. Jmeter函数组件开发
  11. 使用paramiko远程执行
  12. 消息中间件kafka+zookeeper集群部署、测试与应用
  13. JSP之Cookie的实现
  14. unity---背景循环滚动
  15. mysql灾备演练问题
  16. jQuery 省份选择
  17. MongoDB pymongo模块 更新数据
  18. MySQL Binlog和Relaylog生成和清理
  19. MapReduce模型探究--总览
  20. 循环队列 c 实现!!!!

热门文章

  1. HTML5API(4)
  2. aspxpivotgrid 导出excel时,非绑定咧显示为0的情况
  3. JavaScript跨域解决方法大全
  4. java - 线程1打印1-10,当线程打印到5后,线程2打印“hello”,然后线程1继续打印
  5. 【python】日志系统
  6. POJ - 2478
  7. CentOS7.5字体美化
  8. maven创建springboot项目
  9. SPOJ - PHRASES K - Relevant Phrases of Annihilation
  10. 六十三 、异步IO