In many cases the firewall on your computer may be preventing the devices from communicating.
Microsoft has included instructions for allowing applications through the Windows firewall here:
If you're using a Mac, Apple has provided similar instructions here:
If you are running an anti-virus product, such as Norton, you may have to follow a similar process. This is very important as anti-virus applications often have their own firewall and network traffic blockers. It is often easier to fully disable these applications while testing for connection and then reenable and make adjustments later.
It's also possible that the firewall on a wireless access point or other network configuration is preventing communication. If the above information checks out, then you may need to relay the following information to your IT or Network Administration team to adjust the network configuration: Google Cast uses SSDP multicast (UDP 1900) for advertising to Android, mDNS multicast (UDP 5353) for advertising to Windows and Mac, TCP 8008 for the second phase of SSDP, and TCP 8009. The actual Cast screen mirroring uses a randomly-selected UDP port.
Many organizations use networks made up of multiple access points connected to a single Wireless LAN Controller (WLC). In these types of environments, some special considerations may need to be taken to configure the network for Chromecast compatibility. Some additional details on this process can be found in the Cisco help documents linked below:
If you're unable to connect on a public network, and if you have a personal hotspot or a device that can run its own hotspot, you can connect your computer to the network created by the hotspot and mirror over that network.