How can I write my own UDP echo server in MATLAB (not using echoudp)?

2 views (last 30 days)
I'd like to write a program in MATLAB that acts as a server, listening for messages over UDP, doing some local processing and responding to the client with an acknowledgement for each message received.
I have tried to do this by polling in a timer callback function and checking the value of
u.BytesAvailable
(where u is the created UDP object), and also with a BytesAvailableFcn callback.
I am testing this first on one computer using the address '127.0.0.1', port number 8000 and setting
u.EnablePortSharing = 'on';
in both client and server. Eventually, client and server will run on different computers connected with a cable.
The problem is the messages written to port 8000 by the client are not being seen by the server and hence no acknowledgements get sent back to the client.
However, if I use
echoudp('on', 8000);
messages are echoed as expected.
I have tried to find example code for what I am trying to do without success.
Thanks in advance for any help people can give.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!