Dear Goyal,
The optocoupler is a signaling device which can be compared to the old light-in-the-night signaling system used by old mafia in spooky films. It contains two parts, the LED(light emitting diode)which acts as a light source(lets call it a bulb) and there is a light dependent resistor(call it light receiver). When a signal is passed by the PC to turn on an appliance, what happens is that the LED turns on(the bulb glows), thus we get a light signal. The light receiver accepts the signal and converts it back to an electrical signal(I will explain it down below).
Now the other part is the relay, to which this signal goes. As you can, a relay consists of a coil and a switch. The switch is almost similar to the mechanical switch, its the same thing. Now, when the signal from the optocoupler comes out, we pass it through the induction coil. The coil gets charged and it works as an electromagnet. It pulls the switch in the relay to the on position, thus letting the AC to power your appliance.
LDR(Light dependent resistor)-For your knowledge, it is a resistor whose value can change according to the light it receives.
IT is always being supplied voltage. Initially, it doesn't let any current flow through it due to high resistance. What happens is when light is incident on it, the resistance value decreases. This means that current will start flowing through it. ( Visit this link <a href="https://en.wikipedia.org/wiki/Light_Dependent_Resistor" target="_blank" rel="nofollow noopener noreferrer">Light Dependent Resistor</a>)
Now, connect this idea with the optocoupler explanation. When I use an bulb(LED) to create a light signal out of the electric signal I got from the PC, the LDR will convert it back to electrical supply. Now why do we do this? Isn't this a loss? It is a loss, but its worth it. Let me tell you how.
Now, we know that we are using high voltage on the other side of the relay (230V). Suppose, by accident, the relay coil touches the switch, then the high voltage gets a chance to enter into the electronic circuit, which may be only 6V. That creates total destruction in the electronic side. It would burn your electronics, even your PC. So, what will we do? We will isolate the PC from the electronics. How? Using the optocoupler. Now, in the circuit, if there is an optocoupler, what happens is that in such a condition, only the LDR burns out. Then there is no electrical connection with the PC. It is safe!. Now tell me, isn't optocoupler worth t?
If you REALLY understood it, we can go into details. If not, please ask more questions!