diff --git a/examples/tcpsockets/App.js b/examples/tcpsockets/App.js index 9655462..3314cf4 100644 --- a/examples/tcpsockets/App.js +++ b/examples/tcpsockets/App.js @@ -24,6 +24,7 @@ class App extends React.Component { * @param {string | Error} msg */ updateChatter(msg) { + console.log(msg); this.setState({ // @ts-ignore chatter: this.state.chatter.concat([msg]), @@ -35,7 +36,7 @@ class App extends React.Component { this.updateChatter('Client connected to server on ' + JSON.stringify(socket.address())); socket.on('data', (data) => { - this.updateChatter('Server client received: ' + data); + this.updateChatter('Server client received: ' + (data.length < 500 ? data : data.length + ' bytes')); }); socket.on('error', (error) => { @@ -65,7 +66,7 @@ class App extends React.Component { }); client.on('data', (data) => { - this.updateChatter('Client received: ' + data); + this.updateChatter('Client received: ' + (data.length < 500 ? data : data.length + ' bytes')); }); client.on('error', (error) => { diff --git a/examples/tcpsockets/examples/long-data.js b/examples/tcpsockets/examples/long-data.js new file mode 100644 index 0000000..845ae5b --- /dev/null +++ b/examples/tcpsockets/examples/long-data.js @@ -0,0 +1,29 @@ +const net = require('net'); + +const server = new net.Server(); +const client = new net.Socket(); + +const hugeData = 'x'.repeat(5*1024*1024) + +function init() { + server.listen({ port: 0, host: '127.0.0.1', reuseAddress: true }, () => { + const port = server.address()?.port; + if (!port) throw new Error('Server port not found'); + client.connect( + { + port: port, + host: '127.0.0.1', + localAddress: '127.0.0.1', + reuseAddress: true, + // localPort: 20000, + // interface: "wifi", + // tls: true + }, + () => { + client.end(hugeData, 'utf8'); + } + ); + }); +} + +module.exports = { init, server, client }; diff --git a/examples/tcpsockets/examples/main.js b/examples/tcpsockets/examples/main.js index 595e732..2ecb95c 100644 --- a/examples/tcpsockets/examples/main.js +++ b/examples/tcpsockets/examples/main.js @@ -5,7 +5,7 @@ server.on('connection', (socket) => { console.log('Client connected to server on ' + JSON.stringify(socket.address())); socket.on('data', (data) => { - console.log('Server client received: ' + data); + console.log('Server client received: ' + (data.length < 500 ? data : data.length + ' bytes')); }); socket.on('error', (error) => { @@ -34,7 +34,7 @@ client.on('drain', () => { }); client.on('data', (data) => { - console.log('Client received: ' + data); + console.log('Client received: ' + (data.length < 500 ? data : data.length + ' bytes')); }); client.on('error', (error) => {