Beispiel #1
0
 public void SendBroadcast(InternalData message)
 {
     foreach (ClientInfo clientInfo in clientList)
     {
         doSend(NetData.PackageData(getNextMessageID(), message.ToByteArray()), clientInfo);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Sends a message to the server
        /// </summary>
        /// <param name="data">Ithe InternalData object that contains the complete message</param>
        public void Send(InternalData data)
        {
            List <byte[]> msgData = NetData.PackageData(getNextID, data.ToByteArray());

            //Send message to server
            if (msgData != null)
            {
                foreach (byte[] b in msgData)
                {
                    if (b.Length != 1024)
                    {
                        LogEvent("Error: Attempting to send a message of incorrect size");
                    }
                    else
                    {
                        try
                        {
                            //Send it to the server
                            clientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(onSend),
                                                   null);
                        }
                        catch (Exception ex)
                        {
                            LogEvent("Error: Failed to send message.\r\n" + ex);
                            Disconnect("Failed to send message. See log for details.");
                            break; //This message is messed up anyway
                        }
                    }
                }
            }
            else
            {
                LogEvent("Error: Attempting to send a null message");
            }
        }
Beispiel #3
0
        //Public calls for sending
        public void SendDirect(InternalData message, string user_id)
        {
            ClientInfo clientinfo = clientList.Find(x => x.User_ID == user_id);

            if (clientinfo != null)
            {
                doSend(NetData.PackageData(getNextMessageID(), message.ToByteArray()), clientinfo);
            }
        }