-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUDP_Example_OSC_Client_Integer.m
79 lines (68 loc) · 2.6 KB
/
UDP_Example_OSC_Client_Integer.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
% Example for a simple UDP client that sends out an OSC Message with one integer
%
% Create a simple UDP client sending on the loopback interface on port
% 63110 to port 63111. Use an TCP/UDP test tool (e.g. Packet Sender
% https://packetsender.com) or an OSC compatible tool to receive the UDP
% datagrams or the encapsulated OSC message...
%
% -------------------------------------------------------------------------
% 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.
% -------------------------------------------------------------------------
% Add path for OSCMessage implementation
addpath(genpath('../OSCMessage'));
% Create a UDP instance on the loopback interface on port 63110
udpClient = UDP('interface', 'lo', 'port', 63110);
% Don't add a listener funtion
% Just open the UDP instance without start receiving
udpClient.open();
% Create a datagram struct with the necessary fields
datagram.remoteIP = '127.0.0.1';
datagram.remotePort = 63111;
datagram.data = [];
% Set some values to be sent out via UDP
cntr = 0;
iterations = 0;
% Create some data and send it via UDP
while(iterations < 2)
% Create a new OSCMessage
msg = OSCMessage();
msg.addInt32(int32(cntr));
% Convert it to a byte array and store it into the datagram's payload part
datagram.data = msg.toByteArray();
% Send datagram via UDP
udpClient.sendDatagram(datagram);
% Change payload value....
cntr = cntr + 1;
if (mod(cntr, 60) == 0)
cntr = 0;
iterations = iterations+1;
end
pause(1);
end
% Don't forget to close and delete the UDP instance!
% Call those two commands from the command window!!!
udpClient.close();
delete(udpClient);