Serbia's prime minister says he is "shocked" by Hungary's plans to build a fence along the border with Serbia to stop a flow of migrants reaching the country.

Aleksandar Vucic says "walls and fences" are not a solution for the crisis that has seen thousands of migrants from the Middle East and Africa trying to reach the EU while fleeing wars and poverty in their countries.

Announcing the plans, Hungary's Foreign Minister Peter Szijjarto said Wednesday the 4-meter (13-foot) -high fence along the 175-kilometer (109-mile) southern border with Serbia wouldn't contravene any of Hungary's international legal obligations.

The prospect of a barrier leaves a bitter taste in Serbia whose leadership is keen to become part of the EU rather than be cut off from it by a massive fence.