@@ -105,7 +105,7 @@ Send message from ‘nano1’:
105105
106106``` r
107107nano1 $ send(" hello world!" )
108- # > [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
108+ # > [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
109109# > [26] 00 10 00 00 00 01 00 04 00 09 00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64
110110# > [51] 21
111111```
@@ -115,7 +115,7 @@ Receive message using ‘nano2’:
115115``` r
116116nano2 $ recv()
117117# > $raw
118- # > [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
118+ # > [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
119119# > [26] 00 10 00 00 00 01 00 04 00 09 00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64
120120# > [51] 21
121121# >
@@ -146,7 +146,7 @@ Send message from ‘socket1’:
146146
147147``` r
148148send(socket1 , " hello world!" )
149- # > [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
149+ # > [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
150150# > [26] 00 10 00 00 00 01 00 04 00 09 00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64
151151# > [51] 21
152152```
@@ -156,7 +156,7 @@ Receive message using ‘socket2’:
156156``` r
157157recv(socket2 )
158158# > $raw
159- # > [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
159+ # > [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
160160# > [26] 00 10 00 00 00 01 00 04 00 09 00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64
161161# > [51] 21
162162# >
@@ -235,6 +235,7 @@ n$recv(mode = "double")
235235massively-scaleable concurrency framework.
236236
237237``` r
238+
238239s1 <- socket(" pair" , listen = " inproc://nano" )
239240s2 <- socket(" pair" , dial = " inproc://nano" )
240241```
@@ -247,6 +248,7 @@ operation is ongoing, automatically resolving to a final value once
247248complete.
248249
249250``` r
251+
250252# an async receive is requested, but no messages are waiting (yet to be sent)
251253msg <- recv_aio(s2 )
252254msg
@@ -260,6 +262,7 @@ msg$data
260262For a ‘sendAio’ object, the result is stored at ` $result ` .
261263
262264``` r
265+
263266res <- send_aio(s1 , data.frame (a = 1 , b = 2 ))
264267res
265268# > < sendAio >
@@ -276,12 +279,13 @@ For a ‘recvAio’ object, the message is stored at `$data`, and the raw
276279message at ` $raw ` (if kept).
277280
278281``` r
282+
279283# now that a message has been sent, the 'recvAio' automatically resolves
280284msg $ data
281285# > a b
282286# > 1 1 2
283287msg $ raw
284- # > [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
288+ # > [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
285289# > [26] 03 13 00 00 00 02 00 00 00 0e 00 00 00 01 3f f0 00 00 00 00 00 00 00 00 00
286290# > [51] 0e 00 00 00 01 40 00 00 00 00 00 00 00 00 00 04 02 00 00 00 01 00 04 00 09
287291# > [76] 00 00 00 05 6e 61 6d 65 73 00 00 00 10 00 00 00 02 00 04 00 09 00 00 00 01
@@ -298,6 +302,7 @@ and after. This means there is no need to actually wait (block) for an
298302Aio to resolve, as the example below demonstrates.
299303
300304``` r
305+
301306msg <- recv_aio(s2 )
302307
303308# unresolved() queries for resolution itself so no need to use it again within the while loop
@@ -317,6 +322,7 @@ The values may also be called explicitly using `call_aio()`. This will
317322wait for completion of the Aio (blocking).
318323
319324``` r
325+
320326# will wait for completion then return the resolved Aio
321327call_aio(msg )
322328
@@ -343,6 +349,7 @@ separate ‘server’ process running concurrently.
343349function, in this case ` rnorm() ` , before sending back the result.
344350
345351``` r
352+
346353library(nanonext )
347354rep <- socket(" rep" , listen = " tcp://127.0.0.1:6546" )
348355ctxp <- context(rep )
@@ -353,6 +360,7 @@ reply(ctxp, execute = rnorm, send_mode = "raw")
353360request and returns immediately with a ` recvAio ` object.
354361
355362``` r
363+
356364library(nanonext )
357365req <- socket(" req" , dial = " tcp://127.0.0.1:6546" )
358366ctxq <- context(req )
@@ -373,13 +381,14 @@ The return value from the server request is then retrieved and stored in
373381the Aio as ` $data ` .
374382
375383``` r
384+
376385call_aio(aio )
377386
378387aio
379388# > < recvAio >
380389# > - $data for message data
381390aio $ data | > str()
382- # > num [1:100000000] -0.876 0.565 0.656 -1.265 -0.642 ...
391+ # > num [1:100000000] 0.5354 0.1424 0.3993 0.0906 1.6356 ...
383392```
384393
385394As ` call_aio() ` is blocking and will wait for completion, an alternative
@@ -406,6 +415,7 @@ example. A subscriber can subscribe to one or multiple topics broadcast
406415by a publisher.
407416
408417``` r
418+
409419pub <- socket(" pub" , listen = " inproc://nanobroadcast" )
410420sub <- socket(" sub" , dial = " inproc://nanobroadcast" )
411421
@@ -454,6 +464,7 @@ itself is a timed event, and responses received after the timeout are
454464discarded.
455465
456466``` r
467+
457468sur <- socket(" surveyor" , listen = " inproc://nanoservice" )
458469res1 <- socket(" respondent" , dial = " inproc://nanoservice" )
459470res2 <- socket(" respondent" , dial = " inproc://nanoservice" )
@@ -511,21 +522,23 @@ returning immediately with a ‘recvAio’.
511522For normal use, it takes just the URL. It can follow redirects.
512523
513524``` r
525+
514526ncurl(" http://httpbin.org/headers" )
515527# > $raw
516528# > [1] 7b 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 48 6f 73
517529# > [26] 74 22 3a 20 22 68 74 74 70 62 69 6e 2e 6f 72 67 22 2c 20 0a 20 20 20 20 22
518530# > [51] 58 2d 41 6d 7a 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31
519- # > [76] 2d 36 32 36 61 62 33 31 37 2d 31 39 63 35 39 37 30 32 36 63 30 63 64 65 32
520- # > [101] 63 36 32 61 37 33 39 35 35 22 0a 20 20 7d 0a 7d 0a
531+ # > [76] 2d 36 32 36 64 62 31 35 33 2d 32 39 39 31 38 39 63 35 33 61 30 30 35 61 32
532+ # > [101] 38 32 33 65 31 34 38 62 37 22 0a 20 20 7d 0a 7d 0a
521533# >
522534# > $data
523- # > [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-626ab317-19c597026c0cde2c62a73955 \"\n }\n}\n"
535+ # > [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-626db153-299189c53a005a2823e148b7 \"\n }\n}\n"
524536```
525537
526538For advanced use, supports additional HTTP methods such as POST or PUT.
527539
528540``` r
541+
529542res <- ncurl(" http://httpbin.org/post" , async = TRUE , method = " POST" ,
530543 headers = c(`Content-Type` = " application/json" , Authorization = " Bearer APIKEY" ),
531544 data = ' {"key": "value"}' )
535548# > - $raw for raw message
536549
537550call_aio(res )$ data
538- # > [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-626ab317-57e5ea9a6c08c36277518b08 \"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.189.204 \", \n \"url\": \"http://httpbin.org/post\"\n}\n"
551+ # > [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-626db153-400a5a4e7880ba63075877ec \"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"78.145.225.121 \", \n \"url\": \"http://httpbin.org/post\"\n}\n"
539552```
540553
541554In this respect, it may be used as a performant and lightweight method
@@ -550,6 +563,7 @@ communicating with raw sockets. This may be used for connecting to
550563arbitrary non-NNG endpoints.
551564
552565``` r
566+
553567s <- stream(dial = " wss://demo.piesocket.com/v3/channel_1" , textframes = TRUE )
554568s
555569# > < nanoStream >
@@ -619,13 +633,6 @@ set prior to installation if:
619633 want nanonext to download and build a more recent version of
620634 ‘libnng’ than available in system repositories against this.
621635
622- #### Certain ARM architectures
623-
624- If package installation initially fails with an error message of
625- ` unable to load shared object:[ ] undefined symbol: __atomic_fetch_sub_8 `
626- or similar, please set the environment variable
627- ` Sys.setenv(NANONEXT_ARM=1) ` and then proceed with installation again.
628-
629636### Links
630637
631638nanonext on CRAN: < https://cran.r-project.org/package=nanonext > <br />
0 commit comments