Example #1
0
            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);
                }
            }
Example #2
0
            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);
                }
            }