private void SendHeartbeatPack() { //lastSendHeartbeatPackTime = DateTime.Now; byte[] package = PackageProtocol.Encode( PackageType.HEARTBEAT); socket.Send(package, 0, package.Length);//*/ }
internal void Notify <T>(string route, T info) { byte[] packBuff = PackageProtocol.Encode <T>( PackageType.NOTIFY, 0, route, info); socket.Send(packBuff, 0, packBuff.Length); }
public async void OnReceive(byte[] bytes) { try { await UniTask.SwitchToMainThread(); Package package = PackageProtocol.Decode(bytes); //Debug.Log(package.packageType); switch ((PackageType)package.packageType) { case PackageType.HEARTBEAT: //Debug.LogWarning("get HEARTBEAT"); heartBeatServiceGo.HitHole(); break; case PackageType.RESPONSE: ResponseHandler(package); break; case PackageType.PUSH: PushHandler(package); break; case PackageType.HANDSHAKE: HandshakeHandler(package); break; case PackageType.KICK: //HandleKick(package); break; case PackageType.ERROR: ErrorHandler(package); break; default: Debug.Log("No match packageType::" + package.packageType); break; } } catch (Exception e) { await UniTask.SwitchToMainThread(); Debug.LogError(e); throw e; } }
public UniTask <bool> HandsharkAsync(string token) { handshakeTcs = new UniTaskCompletionSource <bool>(); byte[] package = PackageProtocol.Encode <HandShake>( PackageType.HANDSHAKE, 0, "SystemController.handShake", new HandShake() { token = token }); socket.Send(package, 0, package.Length); return(handshakeTcs.Task); }
public UniTask <Package> RequestAsync <T>(uint packID, string route, T info = default, string modelName = null) { lock (packTcs) { UniTaskCompletionSource <Package> pack = new UniTaskCompletionSource <Package>(); byte[] packBuff = PackageProtocol.Encode <T>( PackageType.REQUEST, packID, route, info, modelName); packTcs.Add(packID, pack); socket.Send(packBuff, 0, packBuff.Length); return(pack.Task); } }