2
2
/************************************************************************
3
3
* Copyright 2010-2011 Worlize Inc.
4
4
*
5
- * Licensed under the Apache License, Version 2.0 (the " License" );
5
+ * Licensed under the Apache License, Version 2.0 (the ' License' );
6
6
* you may not use this file except in compliance with the License.
7
7
* You may obtain a copy of the License at
8
8
*
9
9
* http://www.apache.org/licenses/LICENSE-2.0
10
10
*
11
11
* Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an " AS IS" BASIS,
12
+ * distributed under the License is distributed on an ' AS IS' BASIS,
13
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
***********************************************************************/
17
17
18
18
var WebSocketClient = require ( '../../lib/WebSocketClient' ) ;
19
19
20
- console . log ( " WebSocket-Node: Test client for parsing fragmented messages." ) ;
20
+ console . log ( ' WebSocket-Node: Test client for parsing fragmented messages.' ) ;
21
21
22
22
var args = { /* defaults */
23
23
secure : false ,
24
- port : " 8080" ,
25
- host : " 127.0.0.1" ,
26
- " no-defragment" : false ,
24
+ port : ' 8080' ,
25
+ host : ' 127.0.0.1' ,
26
+ ' no-defragment' : false ,
27
27
binary : false
28
28
} ;
29
29
@@ -36,15 +36,15 @@ process.argv.forEach(function(value) {
36
36
}
37
37
} ) ;
38
38
39
- args . protocol = args . secure ? 'wss:' : 'ws:'
39
+ args . protocol = args . secure ? 'wss:' : 'ws:' ;
40
40
41
41
if ( args . help ) {
42
- console . log ( " Usage: ./fragmentation-test-client.js [--host=127.0.0.1] [--port=8080] [--no-defragment] [--binary]" ) ;
43
- console . log ( "" ) ;
42
+ console . log ( ' Usage: ./fragmentation-test-client.js [--host=127.0.0.1] [--port=8080] [--no-defragment] [--binary]' ) ;
43
+ console . log ( '' ) ;
44
44
return ;
45
45
}
46
46
else {
47
- console . log ( " Use --help for usage information." ) ;
47
+ console . log ( ' Use --help for usage information.' ) ;
48
48
}
49
49
50
50
@@ -55,7 +55,7 @@ var client = new WebSocketClient({
55
55
} ) ;
56
56
57
57
client . on ( 'connectFailed' , function ( error ) {
58
- console . log ( " Client Error: " + error . toString ( ) )
58
+ console . log ( ' Client Error: ' + error . toString ( ) ) ;
59
59
} ) ;
60
60
61
61
@@ -65,36 +65,36 @@ var startTime;
65
65
var byteCounter ;
66
66
67
67
client . on ( 'connect' , function ( connection ) {
68
- console . log ( " Connected" ) ;
68
+ console . log ( ' Connected' ) ;
69
69
startTime = new Date ( ) ;
70
70
byteCounter = 0 ;
71
71
72
72
connection . on ( 'error' , function ( error ) {
73
- console . log ( " Connection Error: " + error . toString ( ) ) ;
73
+ console . log ( ' Connection Error: ' + error . toString ( ) ) ;
74
74
} ) ;
75
75
76
76
connection . on ( 'close' , function ( ) {
77
- console . log ( " Connection Closed" ) ;
77
+ console . log ( ' Connection Closed' ) ;
78
78
} ) ;
79
79
80
80
connection . on ( 'message' , function ( message ) {
81
81
if ( message . type === 'utf8' ) {
82
- console . log ( " Received utf-8 message of " + message . utf8Data . length + " characters." ) ;
82
+ console . log ( ' Received utf-8 message of ' + message . utf8Data . length + ' characters.' ) ;
83
83
logThroughput ( message . utf8Data . length ) ;
84
84
requestData ( ) ;
85
85
}
86
86
else {
87
- console . log ( " Received binary message of " + message . binaryData . length + " bytes." ) ;
87
+ console . log ( ' Received binary message of ' + message . binaryData . length + ' bytes.' ) ;
88
88
logThroughput ( message . binaryData . length ) ;
89
89
requestData ( ) ;
90
90
}
91
91
} ) ;
92
92
93
93
connection . on ( 'frame' , function ( frame ) {
94
- console . log ( " Frame: 0x" + frame . opcode . toString ( 16 ) + "; " + frame . length + " bytes; Flags: " + renderFlags ( frame ) )
94
+ console . log ( ' Frame: 0x' + frame . opcode . toString ( 16 ) + '; ' + frame . length + ' bytes; Flags: ' + renderFlags ( frame ) ) ;
95
95
messageSize += frame . length ;
96
96
if ( frame . fin ) {
97
- console . log ( " Total message size: " + messageSize + " bytes." ) ;
97
+ console . log ( ' Total message size: ' + messageSize + ' bytes.' ) ;
98
98
logThroughput ( messageSize ) ;
99
99
messageSize = 0 ;
100
100
requestData ( ) ;
@@ -106,14 +106,14 @@ client.on('connect', function(connection) {
106
106
var duration = ( new Date ( ) ) . valueOf ( ) - startTime . valueOf ( ) ;
107
107
if ( duration > 1000 ) {
108
108
var kiloBytesPerSecond = Math . round ( ( byteCounter / 1024 ) / ( duration / 1000 ) ) ;
109
- console . log ( " Throughput: " + kiloBytesPerSecond + " KBps" ) ;
109
+ console . log ( ' Throughput: ' + kiloBytesPerSecond + ' KBps' ) ;
110
110
startTime = new Date ( ) ;
111
111
byteCounter = 0 ;
112
112
}
113
- } ;
113
+ }
114
114
115
115
function sendUTFCallback ( err ) {
116
- if ( err ) console . error ( " sendUTF() error: " + err ) ;
116
+ if ( err ) { console . error ( ' sendUTF() error: ' + err ) ; }
117
117
}
118
118
119
119
function requestData ( ) {
@@ -144,7 +144,7 @@ client.on('connect', function(connection) {
144
144
flags . push ( '[MASK]' ) ;
145
145
}
146
146
if ( flags . length === 0 ) {
147
- return " ---" ;
147
+ return ' ---' ;
148
148
}
149
149
return flags . join ( ' ' ) ;
150
150
}
@@ -153,11 +153,11 @@ client.on('connect', function(connection) {
153
153
} ) ;
154
154
155
155
if ( args [ 'no-defragment' ] ) {
156
- console . log ( " Not automatically re-assembling fragmented messages." ) ;
156
+ console . log ( ' Not automatically re-assembling fragmented messages.' ) ;
157
157
}
158
158
else {
159
- console . log ( " Maximum aggregate message size: " + client . config . maxReceivedMessageSize + " bytes." ) ;
159
+ console . log ( ' Maximum aggregate message size: ' + client . config . maxReceivedMessageSize + ' bytes.' ) ;
160
160
}
161
- console . log ( " Connecting" ) ;
161
+ console . log ( ' Connecting' ) ;
162
162
163
163
client . connect ( args . protocol + '//' + args . host + ':' + args . port + '/' , 'fragmentation-test' ) ;
0 commit comments