예제 #1
0
 public void BroadcastPacketSingleTarget(int portNo, string broadCastMessage, string callingModule, string destinationIP)
 {
     try
     {
         Socket        socket   = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
         IPEndPoint    remoteEP = new IPEndPoint(IPAddress.Parse(destinationIP), portNo);
         Base64Encoder encoder  = new Base64Encoder(Encoding.ASCII.GetBytes(broadCastMessage));
         byte[]        bytes    = Encoding.ASCII.GetBytes(encoder.GetEncoded());
         socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
         socket.SendTo(bytes, remoteEP);
         socket.Close();
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.ToString());
     }
 }
예제 #2
0
 public void BroadcastPacket(int portNo, string broadCastMessage, string callingModule, DataTable hostIPTable)
 {
     foreach (DataRow row in hostIPTable.Select(""))
     {
         if (row["HOST_IP"].ToString().Trim() != "")
         {
             try
             {
                 Socket        socket   = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                 IPEndPoint    remoteEP = new IPEndPoint(IPAddress.Parse(row["HOST_IP"].ToString().Trim()), portNo);
                 Base64Encoder encoder  = new Base64Encoder(Encoding.ASCII.GetBytes(broadCastMessage));
                 byte[]        bytes    = Encoding.ASCII.GetBytes(encoder.GetEncoded());
                 socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
                 socket.SendTo(bytes, remoteEP);
                 socket.Close();
             }
             catch (Exception exception)
             {
                 Console.WriteLine(exception.ToString());
             }
         }
     }
 }