-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add an example with long data
- Loading branch information
Showing
3 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters