public static void SendDataToIp(string ipAddress, byte[] data)
        {
            HandleBuffer buffer = new HandleBuffer();

            buffer.WriteBytes(data);
            ManageConnection
            .ConnectedClients[ManageConnection.GetIndexOFConnectedClientByIpAddress(ipAddress)]
            .stream.BeginWrite(buffer.ToArray(), 0, buffer.ToArray().Length, null, null);
        }
        public static void SendToRangeOfIds(int[] idRange, byte[] data)
        {
            HandleBuffer buffer = new HandleBuffer();

            buffer.WriteBytes(data);
            idRange.ToList().ForEach(id => ManageConnection
                                     .ConnectedClients[ManageConnection.GetIndexOFConnectedClientById(id)]
                                     .stream.BeginWrite(buffer.ToArray(), 0, buffer.ToArray().Length, null, null));
        }
Пример #3
0
 //todo: refactor this method more generically
 public void SendCommand(string command, bool toClient = false, bool broadcast = false, string ipAddress = "")
 {
     if (command.ToLower() == "quit" && !toClient)
     {
         Command = "quit";
     }
     if (toClient)
     {
         if (broadcast)
         {
             ServerSendData.SendToAll(command.ToByteArray());
         }
         else if (ManageConnection.GetIndexOFConnectedClientByIpAddress(ipAddress) >= 0)
         {
             ServerSendData.SendDataToIp(ipAddress, command.ToByteArray());
         }
     }
     if (command.ToLower() == "list_connections" && !toClient)
     {
         ReportServerMessage(JsonConvert.SerializeObject(ManageConnection.ConnectedClients));
     }
 }