When a modern ship is at sea, it tends to use a lot of fuel. However, when it needs to fill up, it can't just go to the nearest gas station. And, of course, a warship generally wants to stay fairly light, so it can't lug enough diesel to keep itself operational for months on end.
Enter the role of the tanker. When a group of ships (a fleet or a squadron) is at sea, they generally include a tanker, or supply ship. This ship holds the extra fuel, food, ammunition, spare parts, and other equipment. When the other ships need to run to the corner store, they instead contact the tanker and request a Replenishment at Sea (RAS).
At the scheduled time, the ships enter a RAS formation. Generally, this consists of the tanker steaming straight at no less than 10 knots. The vessel(s) that are next in line to refuel will take up station off the port or starboard stern, and await further instruction. Another vessel will take the lifeguard position, watching behind the RASing vessels for men overboard. Any remaining vessels will patrol and watch for enemy contact.
When the signal is given to the receiving ships, they will come alongside the tanker. At this point, everybody on deck will be under cover, with the exception of the station captain. The station captain will show himself long enough to signal the tanker. The station captain of the receiving vessel will show either a flag (during the day) or a light (during the night), then sound one blast on a thunder whistle. This is acknowledged by two blasts from the tanker. One member of the tanker's refuelling crew will fire a gun line to the receiving ship. Once this has been fired, the station crew on the receiving ship will come out from cover, and retrieve the line.
On the tanker side, a messenger line is attached to the gun line. The messenger line will have other lines attached to it, including a distance line, possibly a jackstay, and a cable for the refuelling probe. This will be hauled in by the receiving vessel.
Once the receiving vessel has all their lines, they will attach them to the appropriate parts of their vessel. For example, the refuelling probe's cable will attach to the receptacle on their end for the probe. The jackstay lines will be set up at a jackstay station, etc. They will also take the distance line up to the bow, so that both captains can see it. This line is marked with flags, and enable the vessels to remain within the range of their lines.
Once the probe cable is set up, the probe will go over. This is attached to the fuel line, and will be used to send fuel over. Similar hoses may be sent over for helicopter fuel and water, if they are required by the receiving vessel.
Once the vessel has been refueled, it will return the lines to the tanker, then pass it. The ship that has finished refuelling will become either a sentry vessel or a lifeguard vessel, and another ship will become the receiving vessel. Continue until the fleet has been refuelled.