-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUDP_Example_Echo.m
47 lines (43 loc) · 1.79 KB
/
UDP_Example_Echo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
% Example for an echoing UDP implementation
%
% Create a simple UDP instance listening on the loopback interface on port
% 11724. Use an TCP/UDP test tool (e.g. Packet Sender
% https://packetsender.com) to send single UDP datagrams to this instance.
% The instance will echo the incoming data back to the sender...
%
% -------------------------------------------------------------------------
% Author: Michael Wulf
% Washington University in St. Louis
% Kepecs Lab
%
% Date: 04/15/2022
% Version: 1.0.2
% GitHub: https://github.com/Michael-Wulf/UDP
%
% Copyright (C) 2022 Michael Wulf
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
% MA 02110-1301, USA.
% -------------------------------------------------------------------------
% Create a UDP instance listening on the loopback on port 63110
udpServer = UDP('interface', 'lo', 'port', 63110);
% Add listener funtion
addlistener(udpServer, 'DataReceived', @UDP_Example_Echo_Listener);
% Start the server
udpServer.start();
% Don't forget to close and delete the UDP instance!
% Call those two commands from the command window!!!
%udpServer.stop();
%delete(udpServer);