├── .gitignore ├── .travis.yml ├── site ├── 404.html └── index.html ├── package.json ├── LICENSE ├── lib └── server.js ├── README.md └── tests └── integration.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "node" 5 | 6 | before_script: 7 | - "node lib/server.js &" -------------------------------------------------------------------------------- /site/404.html: -------------------------------------------------------------------------------- 1 | 2 | 404 Not Found 3 |

Not Found

4 |

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

5 | 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tcpbin", 3 | "version": "2.0.0", 4 | "description": "A simple TCP server that echoes whatever it receives", 5 | "author": "Kong ", 6 | "homepage":"http://www.tcpbin.org", 7 | "dependencies": {}, 8 | "devDependencies": { 9 | "mocha": "~5.2.0", 10 | "should": "~13.2.3" 11 | }, 12 | "private": false, 13 | "engines": { 14 | "node": ">=0.10.0" 15 | }, 16 | "license": "MIT", 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/Kong/tcpbin" 20 | }, 21 | "bugs": { 22 | "url": "https://github.com/Kong/tcpbin/issues", 23 | "email": "support@konghq.com" 24 | }, 25 | "scripts": { 26 | "test": "mocha tests --exit" 27 | }, 28 | "main": "lib/server.js" 29 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2013-2019 Kong (https://konghq.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /lib/server.js: -------------------------------------------------------------------------------- 1 | var cluster = require('cluster'); 2 | var net = require('net'); 3 | var dgram = require('dgram'); 4 | var numCPUs = require('os').cpus().length; 5 | 6 | if (cluster.isMaster) { 7 | for (var i = 0; i < numCPUs; i++) { 8 | cluster.fork(); 9 | } 10 | cluster.on('exit', function(worker, code, signal) { 11 | console.log('worker ' + worker.process.pid + ' died'); 12 | }); 13 | } else { 14 | 15 | // TCP Echo 16 | net.createServer(function(socket) { 17 | socket.on('data', function(data) { 18 | socket.write(data); 19 | }); 20 | socket.on('error', function() {}); 21 | }).listen(30000); 22 | 23 | // TCP Info 24 | net.createServer(function(socket) { 25 | socket.on('data', function(data) { 26 | var response = { 27 | "client-ip": socket.remoteAddress, 28 | "data": data.toJSON().data, 29 | "text-data": data.toString(), 30 | "size": data.length 31 | } 32 | socket.write(JSON.stringify(response)); 33 | }); 34 | socket.on('error', function() {}); 35 | }).listen(30001); 36 | 37 | // UDP Echo 38 | var udp_echo_server = dgram.createSocket("udp4"); 39 | udp_echo_server.on("message", function(msg, rinfo) { 40 | udp_echo_server.send(msg, 0, msg.length, rinfo.port, rinfo.address); 41 | }); 42 | udp_echo_server.bind(40000); 43 | 44 | // UDP Info 45 | var udp_info_server = dgram.createSocket("udp4"); 46 | udp_info_server.on("message", function(msg, rinfo) { 47 | var response = JSON.stringify({ 48 | "client-ip": rinfo.address, 49 | "data": msg.toJSON().data, 50 | "text-data": msg.toString(), 51 | "size": msg.length 52 | }); 53 | 54 | var buffer = Buffer.from(response); 55 | udp_info_server.send(buffer, 0, buffer.length, rinfo.port, rinfo.address); 56 | }); 57 | udp_info_server.bind(40001); 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tcpbin(1): TCP/UDP Request & Response Service [![Build Status](https://travis-ci.org/Kong/tcpbin.svg)](https://travis-ci.org/Kong/tcpbin) 2 | 3 | Created and maintained by [Kong](https://konghq.com) 4 | 5 | # FEATURES 6 | 7 | Feature | Description 8 | ------------- | ------------- 9 | TCP echo | Echoes any request sent to **54.175.103.105:30000** 10 | TCP info | Get request info at **54.175.103.105:30001** 11 | UDP echo | Echoes any request sent to **54.175.103.105:40000** 12 | UDP info | Get request info at **54.175.103.105:40001** 13 | 14 | # DESCRIPTION 15 | 16 | This project has been started to help testing TCP and UDP requests in a very easy way. It is very useful for seeing what your clients are sending to TCP/UDP servers and debug problems. It can also be used for mock integration tests. 17 | 18 | # EXAMPLES 19 | 20 | ### $ echo "Text to send to TCP" | ncat 54.175.103.105 30000 21 | 22 | ``` 23 | Text to send to TCP 24 | ``` 25 | 26 | ### $ echo "Get some TCP info" | ncat 54.175.103.105 30001 27 | 28 | ```json 29 | { 30 | "client-ip": "::ffff:41.130.36.121", 31 | "data": [71,101,116,32,115,111,109,101,32,84,67,80,32,105,110,102,111,10], 32 | "text-data": "Get some TCP info\n", 33 | "size": 18 34 | } 35 | ``` 36 | 37 | ### $ echo -n "Text to send to UDP" | nc -4u -w1 54.175.103.105 40000 38 | 39 | ``` 40 | Text to send to UDP 41 | ``` 42 | 43 | ### $ echo -n "Get some UDP info" | nc -4u -w1 54.175.103.105 40001 44 | 45 | ```json 46 | { 47 | "client-ip": "::ffff:41.130.36.121", 48 | "data": [71,101,116,32,115,111,109,101,32,85,68,80,32,105,110,102,111], 49 | "text-data": "Get some UDP info", 50 | "size": 17 51 | } 52 | ``` 53 | 54 | # AUTHOR 55 | 56 | A [Kong](https://konghq.com) project. 57 | 58 | # SEE ALSO 59 | 60 | [Mockbin.com](https://www.mockbin.com/) - Mock, Test & Track HTTP calls 61 | 62 | [Apiembed.com](https://www.apiembed.com/) - Embeddable API Code snippets 63 | 64 | [Konghq.com](https://konghq.com/) - The Cloud-Native API Gateway & Service Mesh 65 | -------------------------------------------------------------------------------- /tests/integration.js: -------------------------------------------------------------------------------- 1 | var should = require('should'); 2 | var net = require('net') 3 | var dgram = require('dgram'); 4 | 5 | describe('Tcpbin', function () { 6 | 7 | describe('TCP', function () { 8 | 9 | it('should echo', function (done) { 10 | var client = new net.Socket(); 11 | client.connect(30000, '127.0.0.1', function() { 12 | client.write('TCP echo test'); 13 | }); 14 | client.on('data', function(data) { 15 | should(data.toString()).equal('TCP echo test'); 16 | done(); 17 | }); 18 | }); 19 | 20 | it('should get info', function (done) { 21 | var client = new net.Socket(); 22 | client.connect(30001, '127.0.0.1', function() { 23 | client.write('TCP info test'); 24 | }); 25 | client.on('data', function(data) { 26 | should(data.toString()).equal('{"client-ip":"::ffff:127.0.0.1","data":[84,67,80,32,105,110,102,111,32,116,101,115,116],"text-data":"TCP info test","size":13}'); 27 | done(); 28 | }); 29 | }); 30 | 31 | }); 32 | 33 | describe('UDP', function () { 34 | 35 | it('should echo', function (done) { 36 | var client = dgram.createSocket('udp4'); 37 | client.on('message', function(message, remote) { 38 | should(message.toString()).equal('UDP echo test'); 39 | done(); 40 | }); 41 | var message = new Buffer.from('UDP echo test'); 42 | client.send(message, 0, message.length, 40000, "127.0.0.1", function(err, bytes) { 43 | if (err) throw err; 44 | }); 45 | }); 46 | 47 | it('should get info', function (done) { 48 | var client = dgram.createSocket('udp4'); 49 | client.on('message', function(message, remote) { 50 | should(message.toString()).equal('{"client-ip":"127.0.0.1","data":[85,68,80,32,105,110,102,111,32,116,101,115,116],"text-data":"UDP info test","size":13}'); 51 | done(); 52 | }); 53 | var message = new Buffer.from('UDP info test'); 54 | client.send(message, 0, message.length, 40001, "127.0.0.1", function(err, bytes) { 55 | if (err) throw err; 56 | }); 57 | }); 58 | 59 | }); 60 | 61 | }); -------------------------------------------------------------------------------- /site/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | tcpbin(1): TCP/UDP Client Testing Service 7 | 44 | 50 | 56 | 57 | 58 | 59 | Fork me on GitHub 60 | 61 | 62 | 63 |
64 |

tcpbin(1): TCP/UDP Request & Response Service

65 |

Created by Mashape

66 | 67 |

FEATURES

68 | 69 | 73 | 77 | 78 |

DESCRIPTION

79 | 80 |

This project has been started to help testing TCP and UDP requests in a very easy way. It is very useful for seeing what your clients are sending to TCP/UDP servers and debug problems. It can also be used for mock integration tests.

81 | 82 |

EXAMPLES

83 | 84 |

$ echo "Text to send to TCP" | ncat 54.175.103.105 30000

85 | 86 |
Text to send to TCP
 87 | 
88 | 89 |

$ echo "Get some TCP info" | ncat 54.175.103.105 30001

90 | 91 |

 92 | {
 93 |   "client-ip": "::ffff:41.130.36.121",
 94 |   "data": [71,101,116,32,115,111,109,101,32,84,67,80,32,105,110,102,111,10],
 95 |   "text-data": "Get some TCP info\n",
 96 |   "size": 18
 97 | }
 98 | 
99 | 100 |

$ echo -n "Text to send to UDP" | nc -4u -w1 54.175.103.105 40000

101 | 102 |
Text to send to UDP
103 | 
104 | 105 |

$ echo -n "Get some UDP info" | nc -4u -w1 54.175.103.105 40001

106 | 107 |

108 | {
109 |   "client-ip": "::ffff:41.130.36.121",
110 |   "data": [71,101,116,32,115,111,109,101,32,85,68,80,32,105,110,102,111],
111 |   "text-data": "Get some UDP info",
112 |   "size": 17
113 | }
114 | 
115 | 116 |

AUTHOR

117 | 118 |

A Mashape project.

119 | 120 |

SEE ALSO

121 | 122 |

Mockbin.com - Mock, Test & Track HTTP calls

123 |

Apiembed.com - Embeddable API Code snippets

124 |

Mashape.com - Largest API Marketplace And Powerful Tools For Private And Public APIs

125 | 126 |
127 | 128 | 129 | --------------------------------------------------------------------------------