liblo  0.31
example_client.c
1 /*
2  * Copyright (C) 2014 Steve Harris et al. (see AUTHORS)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation; either version 2.1 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * $Id$
15  */
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #ifndef WIN32
20 #include <unistd.h>
21 #endif
22 #include "lo/lo.h"
23 
24 const char testdata[6] = "ABCDE";
25 
26 int main(int argc, char *argv[])
27 {
28  /* build a blob object from some data */
29  lo_blob btest = lo_blob_new(sizeof(testdata), testdata);
30 
31  /* an address to send messages to. sometimes it is better to let the server
32  * pick a port number for you by passing NULL as the last argument */
33 // lo_address t = lo_address_new_from_url( "osc.unix://localhost/tmp/mysocket" );
34  lo_address t = lo_address_new(NULL, "7770");
35 
36  if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'q') {
37  /* send a message with no arguments to the path /quit */
38  if (lo_send(t, "/quit", NULL) == -1) {
39  printf("OSC error %d: %s\n", lo_address_errno(t),
41  }
42  } else {
43  /* send a message to /foo/bar with two float arguments, report any
44  * errors */
45  if (lo_send(t, "/foo/bar", "ff", 0.12345678f, 23.0f) == -1) {
46  printf("OSC error %d: %s\n", lo_address_errno(t),
48  }
49 
50  /* send a message to /a/b/c/d with a mixtrure of float and string
51  * arguments */
52  lo_send(t, "/a/b/c/d", "sfsff", "one", 0.12345678f, "three",
53  -0.00000023001f, 1.0);
54 
55  /* send a 'blob' object to /a/b/c/d */
56  lo_send(t, "/a/b/c/d", "b", btest);
57 
58  /* send a 'blob' object to /blobtest */
59  lo_send(t, "/blobtest", "b", btest);
60 
61  /* send a jamin scene change instruction with a 32bit integer argument */
62  lo_send(t, "/jamin/scene", "i", 2);
63  }
64 
65  return 0;
66 }
67 
68 /* vi:set ts=8 sts=4 sw=4: */
lo_blob_new
lo_blob lo_blob_new(int32_t size, const void *data)
Create a new OSC blob type.
lo_blob
void * lo_blob
A object to store an opaque binary data object.
Definition: lo_types.h:52
lo_address_errno
int lo_address_errno(lo_address a)
Return the error number from the last failed lo_send() or lo_address_new() call.
lo.h
lo_address_errstr
const char * lo_address_errstr(lo_address a)
Return the error string from the last failed lo_send() or lo_address_new() call.
lo_send
int lo_send(lo_address targ, const char *path, const char *type,...)
Send a OSC formatted message to the address specified.
lo_address
void * lo_address
A reference to an OSC service.
Definition: lo_types.h:45
lo_address_new
lo_address lo_address_new(const char *host, const char *port)
Declare an OSC destination, given IP address and port number. Same as lo_address_new_with_proto(),...