DatagramSocket problem. Client reading

Hi.

I have Client-Server app.
Server app has DatagramSocket on port 6646, and it reads incoming data:

socket -> read(headerBuffer, maxBytes, false, sender, port);

it gets port and sender, and tries to send data to sender (client) socket back:

socket -> write(sender, port, array, sizeof(DataHeader));

Client app has DatagramSocket, and it is not bound to any port because it is client and gets data only in return from server. And the problem is it sends data, bet never receives:

int amount = socket -> read(headerBuffer, sizeof(DataHeader), false);
// amount is always -1

What am I missing? Please help!

UDP is unidirectional. Client app will need to bind to a different port. There are a few different schemes. you can respond on port num + 1. Or client can bind to random port, and send from that port and then server can respond to that port.

Thank you.
Solution was:
socket -> bindToPort(0); at the client side. Despite client socket can send data without binding, it looks like if you want server to send response you have to force client to bind to a port.