forked from robotology/yarp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyarp_http.dox
148 lines (111 loc) · 4.24 KB
/
yarp_http.dox
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright (C) 2012 IITRBCS
* CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
*
*/
/**
* @page yarp_http YARP ports from your browser
\author Paul Fitzpatrick
YARP ports process HTTP requests with a default interface suitable
for viewing their status, receiving bottle-compatible messages, and
writing bottle-compatible streams.
This is not a general purpose web-server, or something you'd
expose to the general public on the internet.
HTTP service comes is implemented by the http carrier; for other carriers,
see \ref carrier_config.
@section yarp_http_index Index page
To form the URL for a yarp port /PORT, we need to know the IP address
of the machine it lives on, and the (socket) port number it listens to.
One way to get this information is with \ref name_query -
\verbatim
yarp name query /PORT
\endverbatim
For example, let's look at the YARP name server's port, by default called /root
(or whatever "yarp namespace" reports). For me, that is reported to be
here:
\verbatim
registration name /root ip 192.168.1.3 port 10000 type tcp
\endverbatim
Then the URL we need to reach this port is:
\verbatim
http://192.168.1.3:10000
\endverbatim
Visiting that address in a browser, I see something like this:
\verbatim
yarp port /root
(All ports) (connections) (help) (read)
This is /root at tcp://192.168.1.3:10000
There are no outgoing connections
There is an input connection from web to /root using http
\endverbatim
This is the index page for that port, and it reports
information analogous to that given by \ref yarp_ping.
You can view this page for any YARP port.
@section yarp_http_data Sending data
You can send data to a port by appending w?data=... to its base URL.
For example:
\verbatim
http://192.168.1.3:10000/w?data=list
\endverbatim
For my case, that will send a bottle containing the string "list" to
the name server, which will respond with a list of all ports.
Or, if I could send a vector of three floating point numbers 10.0, 30.0, and 40.0 to a port called /adder by finding its address and port number, then visiting:
\verbatim
http://.../w?data=10.0+30.0+40.0
\endverbatim
The format of the data parameter is regular \ref data_rep "Bottle text format" (the "+" symbol is URL encoding for the space character).
@section yarp_http_recv Receiving (low-bandwidth) data
Viewing data sent by a port is done by visiting:
\verbatim
http://.../r
\endverbatim
This will sit and wait for messages and render them as Bottle text format.
For example, doing:
\verbatim
yarpdev --device test_motor --name /motor
\endverbatim
Gives a vector stream at port /motor/state:o. Finding its URL and then
visiting "http://.../r" gives:
\verbatim
yarp port /motor/state:o
(All ports) (connections) (help) (read)
Reading data from port...
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
...
\endverbatim
Buffering behavior varies from browser to browser - YARP does its best
to flush data in a timely fashion but you may have to try different
browsers or browser settings to get good results.
@section yarp_http_recv_images Viewing images in a browser
Image streams can be viewed in the browser if the mjpeg carrier has
been enabled.
For example, doing:
\verbatim
yarpdev --device test_grabber --name /grabber --framerate 5
\endverbatim
We can now view the /grabber port image output at the following URL:
\verbatim
http://.../?action=stream
\endverbatim
and see the image in any browser that understands MJPEG streams
(firefox and chrome for sure).
We can also visit:
\verbatim
http://.../r
\endverbatim
as before, but that will give images in text format, which is slow
and not very helpful...
For the record, the mjpeg carrier currently intercepts any URLs of the
form "http://.../?ac". Other URLs are handled by the default http carrier.
@section yarp_http_custom Custom content
If you do succumb to the temptation to make a mini-webserver, YARP >=
2.3.15 will help you a little. Requests that don't match the patterns
above are passed on to the port in bottle-compatible format; you may
simply reply to them to generate a custom webpage. See the example
web/web_test.cpp. Be aware that this is a new feature of YARP that is
not yet nailed down, so you may need to change your code when using
the next version of YARP.
\include example/web/web_test.cpp
*
*/