i want to know that is there any code possible to write for limited lifetime packets in wsn so that after few hops that packet will automatically dropped?
Use TTL (Time To Live) field in any packet header. Set it to the number of hops you want the packets to be dropped. For example: if TTL=3 then the packet will be dropped after the third hop.