public static void Send(string NetworkKey, object DataObject, TemplatePlayer Player, bool IsSecure = false) { try { byte[] DataBytes; if (DataObject.GetType().Name == "Byte[]") { DataBytes = (byte[])DataObject; } else { DataBytes = SNetPackage.Packaging(DataObject); } TemplateReceiver receiver = new TemplateReceiver(); receiver.NetworkKey = NetworkKey; receiver.DataBytes = DataBytes; receiver.IsSecure = IsSecure; byte[] WriteDataBytes = SNetPackage.Packaging(receiver); ServerSocket.Send(WriteDataBytes, WriteDataBytes.Length, Player.IpPoint); } catch (SocketException ex) { Debug.LogError("Server socket exception:\n" + ex); } }
public static void SendToServer(string NetworkKey, object DataObject = null, bool IsSecure = false) { try { byte[] DataBytes = default; if (DataObject != null) { if (DataObject.GetType().Name == "Byte[]") { DataBytes = (byte[])DataObject; } else { DataBytes = SNetPackage.Packaging(DataObject); } } TemplateReceiver receiver = new TemplateReceiver(); receiver.NetworkKey = NetworkKey; receiver.DataBytes = DataBytes; receiver.IsSecure = IsSecure; byte[] WriteDataBytes = SNetPackage.Packaging(receiver); ClientSocket.Send(WriteDataBytes, WriteDataBytes.Length); } catch (SocketException ex) { Debug.LogError("Client socket exception:\n" + ex); } }
private static async void SocketReceiver() { while (true) { UdpReceiveResult Result = await ClientSocket.ReceiveAsync(); ServerEndPoint = Result.RemoteEndPoint; TemplateReceiver Receive = Framework.Utilities.SNetPackage.Unpacking <TemplateReceiver>(Result.Buffer); if (Receive.IsGaranted) { Receives.Add(Receive); } else { if (Receives.Count <= 50) { if (!Receives.Exists(x => x.NetworkKey == Receive.NetworkKey && x.DataBytes.Length == Receive.DataBytes.Length)) { Receives.Add(Receive); } } } lock (IsLock) { IsEngine = true; } } }
public override void OnServerReceiver(TemplateReceiver Receiver, TemplatePlayer Player) { if (Receiver.NetworkKey != "Player.Print") { return; } Debug.Log("NetworkKey: " + Receiver.NetworkKey + " - " + SNetPackage.Unpacking <string>(Receiver.DataBytes)); }
public static void AddPlayer(TemplateReceiver Receiver, IPEndPoint IpPlayerPoint) { Players.Add(new TemplatePlayer { Id = Players.Count + 1, Ip = IpPlayerPoint.Address.ToString(), Port = IpPlayerPoint.Port, IpPoint = IpPlayerPoint }); Debug.Log("Player is connected - " + IpPlayerPoint.Address.ToString() + ":" + IpPlayerPoint.Port); }
/** * ONLY SERVER */ public virtual void OnServerReceiver(TemplateReceiver Receiver, TemplatePlayer Player) { }
/** * ONLY CLIENT */ public virtual void OnClientReceiver(TemplateReceiver Receiver, IPEndPoint IpServerPoint) { }