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 SendToRangeOfIpAdresses(string[] ipRange, byte[] data)
        {
            HandleBuffer buffer = new HandleBuffer();

            buffer.WriteBytes(data);
            ipRange.ToList().ForEach(ipAddress => ManageConnection
                                     .ConnectedClients[ManageConnection.GetIndexOFConnectedClientByIpAddress(ipAddress)]
                                     .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));
     }
 }