// Use this for initialization void Start() { oper = new Oper(this); Input.multiTouchEnabled = true; self = GetComponent <Transform>(); selfCamera = GetComponent <Camera>(); kcpSocket = GetComponent <KcpSocket>(); kcpSocket.Init(ip, 8888, (Action <List <byte[]>, int>)((List <byte[]> a, int b) => { for (int i = 0; i < a.Count; i++) { // deal message( sendFormat="%f %f %f %d %d" -- frame pos.x pos.y dir.angle dir.speed ) string msg = System.Text.Encoding.Default.GetString(a[i]); string [] fposdir = msg.Split(); float x = float.Parse(fposdir[1]); float y = float.Parse(fposdir[2]); double deltaX = x - self.position.x; double deltaY = y - self.position.y; double delta = Math.Pow(deltaX * deltaX + deltaY * deltaY, 0.5); if (delta > 0.1) { Debug.Log("delta=" + delta); } offsetX = deltaX; offsetY = deltaY; fakeFrame = 120; dir.angle = int.Parse(fposdir[3]); dir.speed = int.Parse(fposdir[4]); cube.rotation = Quaternion.Euler(0, 0, dir.angle); } })); kcpSocket.Connect(5000, onConnect); }
public void Redirect(string ip, int port) { if (kcp == null) { kcp = new KcpServer <KcpSocket>(0); kcp.Run(1); } if (link == null) { var address = IPAddress.Parse(ip); link = kcp.FindOrCreateLink(new IPEndPoint(address, port)); link.Send(new byte[1], 0); } else { var add = IPAddress.Parse(ip); link.endpPoint.Address = add; link.endpPoint.Port = port; var b = add.GetAddressBytes(); unsafe { fixed(byte *bp = &b[0]) link.ip = *(Int32 *)bp; } link.port = port; link.envelope.Clear(); link.metaData.Clear(); } }
public void Connection(string ip, int port) { UniId = SystemInfo.deviceUniqueIdentifier; var address = IPAddress.Parse(ip); var kcp = new KcpServer <KcpSocket>(0, 1); kcp.Run(); link = kcp.FindOrCreateLink(new IPEndPoint(address, port)); link.Send(new byte[1], 0); }
public void Connection(string ip, int port) { if (kcp == null) { kcp = new KcpServer <KcpSocket>(0); kcp.Run(1); } var address = IPAddress.Parse(ip); link = kcp.FindOrCreateLink(new IPEndPoint(address, port)); link.Send(new byte[1], 0); }
public void Close() { if (KcpListener.Instance != null) { KcpListener.Instance.Dispose(); } //Application.logMessageReceived -= Log; if (link != null) { link.Dispose(); } link = null; }
public void Connection(string ip, int port) { var address = IPAddress.Parse(ip); KcpServer.CreateLink = (o) => { return(new KcpSocket(o)); }; var kcp = new KcpServer(0, 0, 1); link = kcp.CreateNewLink(new IPEndPoint(address, port)) as KcpSocket; link.SendNull(ProCmd.ServerIp, MessageType.Pro); //LoginTable login = new LoginTable(); //login.user = "******"; //login.pass = "******"; //Instance.SendObject<LoginTable>(DefCmd.Login, MessageType.Def, login); }