public SimpleUDPClient(IPEndPoint ip, KCPClient k) { remoteEnd = ip; client = k; udpClient = new UdpClient(0); recvThread = new Thread(RecvThread); recvThread.Start(); sendThread = new Thread(SendThread); sendThread.Start(); }
/// <summary> /// 下层自上层的断开连接 /// 是否重连 /// </summary> private void CloseEventHandler() { if (state != WorldState.Closed) { kcpClient = new KCPClient(rc.GetMainLoop(), this); kcpClient.closeEventHandler = this.CloseEventHandler; kcpClient.Connect(ClientApp.Instance.remoteServerIP, ClientApp.Instance.remoteKCPPort); //重新初始化 食物的状态请求 } }
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 StartUdp(int type) { if (type == 1) { if (udp == null) { udp = new UClient(this); udp.Handlers = tcp_handle; } } else if (type == 2) { kcp = new KCPClient(); kcp.Event += Client_Event; kcp.Connect("192.168.2.91", 7566, (uint)main.entity_id, main.entity_id); } }
void QuitWorld() { Debug.LogError("QuitWorld"); state = WorldState.Closed; if (rc != null) { rc.evtHandler = null; rc.msgHandler = null; rc.Disconnect(); rc = null; } if (udpClient != null) { udpClient.Quit(); udpClient = null; } if (kcpClient != null) { kcpClient.Close(); kcpClient = null; } }
public NetBase(string _ip, int _port, float _HeartTime, float _DisConnTime, NetWorkType _type) { ip = _ip; port = _port; type = _type; DisConnTime = _DisConnTime * 1000; HeartTime = _HeartTime * 1000; lock (msg_obj) { } switch (type) { case NetWorkType.Kcp: kcp = new KCPClient(this); kcp.DisConnectEvent += DisConn; kcp.ConnectResultEvent += ConnectBack; break; case NetWorkType.Tcp: tcp = new TcpClient(this); tcp.DisConnectEvent += DisConn; tcp.ConnectResultEvent += ConnectBack; break; } }
public void End() { Debug.Log("====end====="); ClearMsg(); handlers = null; switch (type) { case NetWorkType.Kcp: if (kcp != null) { kcp.End(); kcp = null; } break; case NetWorkType.Tcp: if (tcp != null) { tcp.End(); tcp = null; } break; } }