ACR_ServerCommunicator.SocketIo.SendMessage C# (CSharp) Method

SendMessage() public static method

Send a message to an arbitrary destination using the server's data socket.
public static SendMessage ( byte Message, IPAddress Destination, int DestinationPort ) : void
Message byte Supplies the bytes to send.
Destination System.Net.IPAddress Supplies the destination network address. ///
DestinationPort int Supplies the destination port. ///
return void
        public static void SendMessage(byte[] Message, IPAddress Destination, int DestinationPort)
        {
            sockaddr_in sin = new sockaddr_in()
            {
                sin_family = AF_INET,
                sin_port = (ushort)IPAddress.HostToNetworkOrder((short)DestinationPort),
#pragma warning disable 618
                sin_addr = (uint)Destination.Address,
#pragma warning restore 618
                sin_zero = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 }
            };

            SendMessage(Message, sin);
        }

Same methods

SocketIo::SendMessage ( byte Message, sockaddr_in Destination ) : void

Usage Example

        /// <summary>
        /// Send a direct message to a server.  Failures are ignored.
        /// </summary>
        /// <param name="Data">Supplies the message payload.</param>
        /// <param name="Server">Supplies the destination server.</param>
        private void SendMessageToServer(byte[] Data, GameServer Server)
        {
            try
            {
                IPAddress Address;

                if (Server.ServerId == LocalServerId)
                {
                    Address = IPAddress.Loopback;
                }
                else
                {
                    Address = Server.GetIPAddress();
                }

                SocketIo.SendMessage(Data, Address, Server.ServerPort);
            }
            catch
            {
            }
        }