STP queries

Could anyone please let me know , how the BPDUS are exchanged in STP
Are the BPDUs exchanged only with their neighbors to which they are connected

The answer to this depends on what flavor of spanning-tree is running. Since you asked about STP, I will talk about that as opposed to RSTP.

When switches first start up, they need to elect a root bridge. During this phase, BPDUs are sent out all interfaces. Once a Root Bridge is elected, it is the job of the Root Bridge to originate BPDUs. These are sent to directly connected switches via the Root Bridge’s Designated Ports. The neighboring switches will receive the BPDU via their Root Port. The switch will then create a copy of this BPDU, increase the “age count” of it, and send it out all of its own Designated Ports. This cycle will continue until a the BPDUs have reached the edge of the network, or until the “age count” of the BPDU has exceeded the Max Age value specified by the Root Bridge.

One exception to this would be when a new switch boots up into an existing established STP topology, and falsely claims to be the root bridge (because it hasn’t discovered the root bridge yet). In this case, a neighboring switch (even if it is not the true Root Bridge) will actually generate a BPDU to tell the new switch the information it needs.

There are two circumstances where a port will not send BPDUs: 1) It is in a Blocking state, 2) BPDU filtering has been enabled on the port.