File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ class App extends React.Component {
24
24
* @param {string | Error } msg
25
25
*/
26
26
updateChatter ( msg ) {
27
+ console . log ( msg ) ;
27
28
this . setState ( {
28
29
// @ts -ignore
29
30
chatter : this . state . chatter . concat ( [ msg ] ) ,
@@ -35,7 +36,7 @@ class App extends React.Component {
35
36
this . updateChatter ( 'Client connected to server on ' + JSON . stringify ( socket . address ( ) ) ) ;
36
37
37
38
socket . on ( 'data' , ( data ) => {
38
- this . updateChatter ( 'Server client received: ' + data ) ;
39
+ this . updateChatter ( 'Server client received: ' + ( data . length < 500 ? data : data . length + ' bytes' ) ) ;
39
40
} ) ;
40
41
41
42
socket . on ( 'error' , ( error ) => {
@@ -65,7 +66,7 @@ class App extends React.Component {
65
66
} ) ;
66
67
67
68
client . on ( 'data' , ( data ) => {
68
- this . updateChatter ( 'Client received: ' + data ) ;
69
+ this . updateChatter ( 'Client received: ' + ( data . length < 500 ? data : data . length + ' bytes' ) ) ;
69
70
} ) ;
70
71
71
72
client . on ( 'error' , ( error ) => {
Original file line number Diff line number Diff line change
1
+ const net = require ( 'net' ) ;
2
+
3
+ const server = new net . Server ( ) ;
4
+ const client = new net . Socket ( ) ;
5
+
6
+ const hugeData = 'x' . repeat ( 5 * 1024 * 1024 )
7
+
8
+ function init ( ) {
9
+ server . listen ( { port : 0 , host : '127.0.0.1' , reuseAddress : true } , ( ) => {
10
+ const port = server . address ( ) ?. port ;
11
+ if ( ! port ) throw new Error ( 'Server port not found' ) ;
12
+ client . connect (
13
+ {
14
+ port : port ,
15
+ host : '127.0.0.1' ,
16
+ localAddress : '127.0.0.1' ,
17
+ reuseAddress : true ,
18
+ // localPort: 20000,
19
+ // interface: "wifi",
20
+ // tls: true
21
+ } ,
22
+ ( ) => {
23
+ client . end ( hugeData , 'utf8' ) ;
24
+ }
25
+ ) ;
26
+ } ) ;
27
+ }
28
+
29
+ module . exports = { init, server, client } ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ server.on('connection', (socket) => {
5
5
console . log ( 'Client connected to server on ' + JSON . stringify ( socket . address ( ) ) ) ;
6
6
7
7
socket . on ( 'data' , ( data ) => {
8
- console . log ( 'Server client received: ' + data ) ;
8
+ console . log ( 'Server client received: ' + ( data . length < 500 ? data : data . length + ' bytes' ) ) ;
9
9
} ) ;
10
10
11
11
socket . on ( 'error' , ( error ) => {
@@ -34,7 +34,7 @@ client.on('drain', () => {
34
34
} ) ;
35
35
36
36
client . on ( 'data' , ( data ) => {
37
- console . log ( 'Client received: ' + data ) ;
37
+ console . log ( 'Client received: ' + ( data . length < 500 ? data : data . length + ' bytes' ) ) ;
38
38
} ) ;
39
39
40
40
client . on ( 'error' , ( error ) => {
You can’t perform that action at this time.
0 commit comments