"readme":"# proxysocket\r\n\r\n[![Join the chat at https://gitter.im/krisives/proxysocket](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/krisives/proxysocket?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\r\n\r\n`proxysocket` is a nodejs module for seamlessly making socket connections via a\r\nSOCKS5 proxy. Use it in place of a regular `net.Socket` to easily talk over\r\nTor or an SSH tunnel.\r\n\r\n## Install\r\n\r\nAvailable on npm for easy install:\r\n\r\n\tnpm install proxysocket\r\n\r\nYou can also download a [release](https://github.com/krisives/proxysocket/releases) manually and\r\nextract it as `proxysocket` has no dependencies.\r\n\r\n## Usage\r\n\r\nBecause `proxysocket` provides the same API as a regular `net.Socket` object\r\nyou can use it in many places where sockets and streams are used.\r\n\r\n### Making a Socket\r\n\r\nCreate a new socket that will use the proxy:\r\n\r\n\tvar proxysocket = require('proxysocket');\r\n\tvar socket = proxysocket.create('localhost', 9050);\r\n\r\nThe returned object behaves like an ordinary `net.Socket` object.\r\nFor example, you can call `connect()` or listen for events:\r\n\r\n\tsocket.connect(80, 'website.com', function () {\r\n\t\t// Connected\r\n\t});\r\n\r\n\tsocket.on('data', function (data) {\r\n\t\t// Receive data\r\n\t});\r\n\r\nAlso note if you're using Tor it's fine to pass `.onion` hosts:\r\n\r\n\tsocket.connect(6667, 'p4fsi4ockecnea7l.onion');\r\n\r\n\r\n### Making HTTP Requests\r\n\r\nYou can use `proxysocket.createAgent()` to create an object\r\nlike `http.Agent` which will make proxy sockets for you when using\r\n`http.request()`. Here is an example:\r\n\r\n\tvar proxysocket = require('proxysocket');\r\n\tvar http = require('http');\r\n\tvar agent = proxysocket.createAgent();\r\n\r\n\thttp.request({\r\n\t\thost: 'foo.com',\r\n\t\tagent: agent\r\n\t});\r\n\r\n### Chaining\r\n\r\nIt's fine to pass one proxysocket to another:\r\n```js\r\n\tvar socket1 = proxysocket.create('socks1addr', 9050)\r\n\tvar socket2 = proxysocket.create('socks2addr', 9050, socket1)\r\n\r\n\tsocket2.connect(80, 'example.com', function () {\r\n\t\t// connected\r\n\t})\r\n```\r\nThe resulting chain:\r\nsocksaddr1:9050 -> socksaddr2:9050 -> example.com\r\n\r\n## API\r\n\r\n### proxysocket.create(socksHost, socksPort, socket)\r\n\r\nCreate a new socket object that uses a SOCKS5 proxy provided.\r\n\r\n* `socksHost` is the host of the proxy. Default is `localhost`\r\n* `socksPort` is the port of the proxy. Default is `9050`\r\n* `socket` can be an existing `net.Socket` object or any object with\r\nthe same interface (e.g. `proxysocket`). Default is a `new Socket()`\r\n\r\n### proxysocket.createAgent(socksHost, socksPort)\r\n\r\nReturns an object like `http.Agent` which makes new sockets\r\nusing `proxysocket.create()` as needed.\r\n\r\n### socket\r\n\r\nThe object returned from `proxysocket.create()` is just like a regular\r\n`net.Socket`. This documentation lists additions to the API.\r\n\r\n*Note This documentation doesn't list all of the methods, properties,\r\nor events of `net.Socket`, `Readable` or `Writable`. See the nodejs\r\nAPI reference for those modules.*\r\n\r\n### socket.socksHost\r\n\r\nGet the host address of the proxy. By default this will be `localhost`.\r\n\r\n### socket.socksPort\r\n\r\nGet the port of the proxy. By default this will be `9050`.\r\n\r\n### socket.realSocket\r\n\r\nGet the underlying raw `net.Socket` connection to the proxy. You don't need\r\nto use this and instead should listen on `this` socket instead.\r\n\r\n### socket 'socksdata' event\r\n\r\n`socksdata` is emitted whenever underlying data is received from the proxy\r\nbefore the socket is ready for use. This is mainly here for debugging and you\r\nshould use the `data` event instead.\r\n\r\n## Contributing\r\n\r\nPlease fork and make a pull request if you have anything cool to add. You're\r\nalso welcome to join the [Gitter](https://gitter.im/krisives/proxysocket?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) chat.\r\n",