{"name":"udp-request","version":"2.0.0","description":"Small module for making requests/responses over UDP","main":"index.js","dependencies":{"passthrough-encoding":"^1.2.0"},"devDependencies":{"standard":"^12.0.1","tape":"^4.9.1"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/udp-request.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/udp-request/issues"},"homepage":"https://github.com/mafintosh/udp-request","gitHead":"78ebc1d67bcc7dc8e8d5d8e724d260fd8e9bb8d6","_id":"udp-request@2.0.0","_npmVersion":"6.2.0","_nodeVersion":"10.9.0","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"integrity":"sha512-v4LagfW0q9FWsli5W+FdKzo+X+6UMHhi00Bb6NQm7QSkr/SFUP4fNnpY5BT64Gcrnv4h7XnWKqTu80no/kNcyw==","shasum":"809cbd3cedb12e88ecaa56e89660d7e4d1838185","tarball":"http://registry-npm.ywwl.com/udp-request/download/udp-request-2.0.0.tgz","fileCount":7,"unpackedSize":12608,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJboY4bCRA9TVsSAnZWagAAZd8P/04nuewFLu3fXFn0Ykye\nVJPJjunE8BLJSGdLCArBOszlYwvjQ09XkgGXGHKYTc+xIC/OY3/9wIHIS4oQ\nuUzIV/FktReqbdKl63cHJ66VnUiMEP+N4pXC2b+60J+NcGe8cN174/7aCwcx\nMlujBwuDtQLpjozlorOg8qt/T4MbrROObUxrtI9FcxEBCG1aP5oE61cDvBIe\njiHGQDhWwj4vLHNLyi83H6oLsL7gvCMw7VOfF03cvW9Ew3BsUcbwlNY0FlOT\nSDpjZNEp2qHu8FZedMIOEvULgARY5WeaxocrlKZqlyVdyZI5sz2XqVxesbYj\n6gR2Lj7GTbC3exgOjsrzCTRakZCQowUIDkpt+tbZFHTQJoCriamEvlVcYeCU\nBd5QLY6aAs9ovElezGNbX+KA2c5Rj2fzl3mgh50Z3gcjX0QAmyBO/7+sX7KF\n5CB940lF7ZqB+8Di6DgbaopqnAqXuGL3mlSRLec8+mnpxsQnW+NbssV40SJL\ni8MaHH1Z7D3LpZTqx9IQW9LS0VRrlewThdpeYM4Kss/ZYQk7nJ360EYGGaR/\nIPSF2Ak+92gGWM+YD7S4CT3Rhny1e6PwsKOwM6rQksGYkBI9KPF4mYDYjYZS\nK/P0y7lkm5n2/gXbnQHx+wzyGh//4eiz48Ofteqs1/pvpVWLYFVNzDuPkRgb\niBMi\r\n=HwaA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHVWC+EMz0M4HnhNkIKsItiZLl9qPQWE/wOOQy4Fa7tXAiEAi/4v/cqloqhgHxq3DjJRzWY9s6NOUsHWWhA1n4Kb9To="}],"size":4029,"noattachment":false,"key":"/udp-request/-/udp-request-2.0.0.tgz"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/udp-request_2.0.0_1537314330261_0.7376458963706833"},"_hasShrinkwrap":false,"readme":"# udp-request\n\nSmall module for making requests/responses over UDP\n\n```\nnpm install udp-request\n```\n\n[![build status](http://img.shields.io/travis/mafintosh/udp-request.svg?style=flat)](http://travis-ci.org/mafintosh/udp-request)\n\n## Usage\n\n``` js\nvar udp = require('udp-request')\nvar socket = udp()\n\nsocket.on('request', function (request, peer) {\n  console.log('request:', request.toString())\n  socket.response('echo: ' + request.toString(), peer)\n})\n\nsocket.listen(10000, function () {\n  socket.request('hello', {port: 10000, host: '127.0.0.1'}, function (err, response) {\n    console.log('response', response.toString())\n    socket.destroy()\n  })\n})\n```\n\n## API\n\n#### `var socket = udp([options])`\n\nCreate a new request/response udp socket. Options include:\n\n``` js\n{\n  timeout: 1000, // request timeout\n  socket: udpSocket, // supply your own udp socket\n  retry: true, // retry requests if they time out. defaults to false\n  requestEncoding: someEncoder, // abstract-encoding compliant encoder\n  responseEncoding: someEncoder, // abstract-encoding compliant encoder\n}\n```\n\n#### `var id = socket.request(buffer, peer, [options], [callback])`\n\nSend a new request. `buffer` is the request payload and `peer` should be an object containing `{port, host}`.\nWhen the response arrives (or the request times out) the callback is called with the following arguments\n\n``` js\ncallback(error, response, peer)\n```\n\nOptions include:\n\n``` js\n{\n  retry: true\n}\n```\n\n#### `socket.response(buffer, peer)`\n\nSend a response back to a request.\n\n#### `socket.cancel(id)`\n\nCancels a pending request.\n\n#### `socket.on('request', buffer, peer)`\n\nEmitted when a new request arrives. Call the above `.response` with the same peer object to send a response back to this request.\n\n#### `socket.on('response', buffer, peer)`\n\nEmitted when any response arrives.\n\n#### `socket.on('error', err)`\n\nEmitted when a critical error happens.\n\n#### `socket.on('warning', err)`\n\nEmitted when a non critical error happens (you usually do not need to listen for this).\n\n#### `socket.on('close')`\n\nEmitted when the request socket closes (after it is destroyed).\n\n#### `socket.on('listening')`\n\nEmitted when the socket is listening.\n\n#### `socket.listen([port], [callback])`\n\nListen on a specific port. If port is omitted a random one will be used.\n\n#### `socket.destroy()`\n\nCompletely destroy the request socket (cancels all pending requests).\n\n## License\n\nMIT\n","publish_time":1537314330353,"_cnpm_publish_time":1537314330353,"dist-tags":{"latest":"2.0.0"}}