public void Start(string host, UInt16 port, uint index, int key) { client = new KCPClient(); client.Event += client_Event; client.Connect(host, port, index, key); while (true) { client.Update(); System.Threading.Thread.Sleep(30); } }
public void Update() { client.Update(); }
public void Update() { if (tcp.state == -1) {//断线,重新连接 tcp.ConnectAsync(ip, port); tcp.state = 0; } else if (tcp.state == 10) {//连接成功,开始登陆 tcp.state = 11; Debug.Log("==Tcp连接成功,开始登陆=="); tcp.Send <LoginRequest>(10, new LoginRequest() { id = 0 }); } else if (tcp.state == 20) {//登陆成功 Debug.Log("==Tcp登陆成功=="); StartUdp(2); tcp.state = 21; } else if (tcp.state == 30) { main.GameUpdae(); } tcp.Update(); if (type == 1) { if (udp != null) { if (udp.state == 10) {//连接成功,开始登陆 Debug.Log("==开始登陆=="); udp.state = 11; udp.Send <LoginRequest>(11, new LoginRequest() { id = main.entity_id }); } else if (udp.state == 20) {//登陆成功 Debug.Log("==Udp登陆成功=="); main.CreateObj(main.entity_id); udp.state = 30; } else if (udp.state == 30) { main.GameUpdae(); } udp.Update(); } } else if (type == 2) { if (kcp != null) { if (kcp.state == 10) {//连接成功,开始登陆 Debug.Log("==开始登陆=="); kcp.state = 11; kcp.Send <LoginRequest>(12, new LoginRequest() { id = main.entity_id }); } else if (kcp.state == 20) {//登陆成功 Debug.Log("==Udp登陆成功=="); main.CreateObj(main.entity_id); kcp.state = 30; } else if (kcp.state == 30) { main.GameUpdae(); } kcp.Update(); } } }