File tree Expand file tree Collapse file tree 8 files changed +72
-43
lines changed
next/javascript-api/k6-experimental/websockets/websocket
v0.47.x/javascript-api/k6-experimental/websockets/websocket
v0.48.x/javascript-api/k6-experimental/websockets/websocket
src/data/markdown/docs/02 javascript api/07 k6-experimental/05 websockets/10 WebSocket Expand file tree Collapse file tree 8 files changed +72
-43
lines changed Original file line number Diff line number Diff line change @@ -19,22 +19,24 @@ _A k6 script that initiates a WebSocket connection and sets up a handler for the
19
19
import { WebSocket } from ' k6/experimental/websockets' ;
20
20
21
21
export default function () {
22
- const ws = new WebSocket (' ws ://localhost:10000 ' );
22
+ const ws = new WebSocket (' wss ://test-api.k6.io/ws/crocochat/publicRoom/ ' );
23
23
24
24
ws .onping = () => {
25
25
console .log (' A ping happened!' );
26
+ ws .close ();
26
27
};
27
- }
28
- ```
29
-
30
- {{< /code >}}
31
28
32
- The preceding example uses a WebSocket echo server, which you can run with the following command:
29
+ ws .onclose = () => {
30
+ console .log (' WebSocket connection closed!' );
31
+ }
33
32
34
- {{< code >}}
35
-
36
- ``` bash
37
- $ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server
33
+ ws .onopen = () => {
34
+ ws .send (JSON .stringify ({ ' event' : ' SET_NAME' , ' new_name' : ` Croc ${ __VU } ` }));
35
+ }
36
+ ws .onerror = (err ) => {
37
+ console .log (err)
38
+ }
39
+ }
38
40
```
39
41
40
- {{< /code >}}
42
+ {{< /code >}}
Original file line number Diff line number Diff line change @@ -23,7 +23,12 @@ export default function () {
23
23
24
24
ws .onpong = () => {
25
25
console .log (' A pong happened!' );
26
+ ws .close ();
26
27
};
28
+
29
+ ws .onopen = () => {
30
+ ws .ping ();
31
+ }
27
32
}
28
33
```
29
34
Original file line number Diff line number Diff line change @@ -19,22 +19,24 @@ _A k6 script that initiates a WebSocket connection and sets up a handler for the
19
19
import { WebSocket } from ' k6/experimental/websockets' ;
20
20
21
21
export default function () {
22
- const ws = new WebSocket (' ws ://localhost:10000 ' );
22
+ const ws = new WebSocket (' wss ://test-api.k6.io/ws/crocochat/publicRoom/ ' );
23
23
24
24
ws .onping = () => {
25
25
console .log (' A ping happened!' );
26
+ ws .close ();
26
27
};
27
- }
28
- ```
29
-
30
- {{< /code >}}
31
28
32
- The preceding example uses a WebSocket echo server, which you can run with the following command:
29
+ ws .onclose = () => {
30
+ console .log (' WebSocket connection closed!' );
31
+ }
33
32
34
- {{< code >}}
35
-
36
- ``` bash
37
- $ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server
33
+ ws .onopen = () => {
34
+ ws .send (JSON .stringify ({ ' event' : ' SET_NAME' , ' new_name' : ` Croc ${ __VU } ` }));
35
+ }
36
+ ws .onerror = (err ) => {
37
+ console .log (err)
38
+ }
39
+ }
38
40
```
39
41
40
- {{< /code >}}
42
+ {{< /code >}}
Original file line number Diff line number Diff line change @@ -23,7 +23,12 @@ export default function () {
23
23
24
24
ws .onpong = () => {
25
25
console .log (' A pong happened!' );
26
+ ws .close ();
26
27
};
28
+
29
+ ws .onopen = () => {
30
+ ws .ping ();
31
+ }
27
32
}
28
33
```
29
34
Original file line number Diff line number Diff line change @@ -19,22 +19,24 @@ _A k6 script that initiates a WebSocket connection and sets up a handler for the
19
19
import { WebSocket } from ' k6/experimental/websockets' ;
20
20
21
21
export default function () {
22
- const ws = new WebSocket (' ws ://localhost:10000 ' );
22
+ const ws = new WebSocket (' wss ://test-api.k6.io/ws/crocochat/publicRoom/ ' );
23
23
24
24
ws .onping = () => {
25
25
console .log (' A ping happened!' );
26
+ ws .close ();
26
27
};
27
- }
28
- ```
29
-
30
- {{< /code >}}
31
28
32
- The preceding example uses a WebSocket echo server, which you can run with the following command:
29
+ ws .onclose = () => {
30
+ console .log (' WebSocket connection closed!' );
31
+ }
33
32
34
- {{< code >}}
35
-
36
- ``` bash
37
- $ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server
33
+ ws .onopen = () => {
34
+ ws .send (JSON .stringify ({ ' event' : ' SET_NAME' , ' new_name' : ` Croc ${ __VU } ` }));
35
+ }
36
+ ws .onerror = (err ) => {
37
+ console .log (err)
38
+ }
39
+ }
38
40
```
39
41
40
- {{< /code >}}
42
+ {{< /code >}}
Original file line number Diff line number Diff line change @@ -23,7 +23,12 @@ export default function () {
23
23
24
24
ws .onpong = () => {
25
25
console .log (' A pong happened!' );
26
+ ws .close ();
26
27
};
28
+
29
+ ws .onopen = () => {
30
+ ws .ping ();
31
+ }
27
32
}
28
33
```
29
34
Original file line number Diff line number Diff line change @@ -17,21 +17,24 @@ _A k6 script that initiates a WebSocket connection and sets up a handler for the
17
17
import { WebSocket } from ' k6/experimental/websockets' ;
18
18
19
19
export default function () {
20
- const ws = new WebSocket (' ws ://localhost:10000 ' );
20
+ const ws = new WebSocket (' wss ://test-api.k6.io/ws/crocochat/publicRoom/ ' );
21
21
22
22
ws .onping = () => {
23
23
console .log (' A ping happened!' );
24
+ ws .close ();
24
25
};
25
- }
26
- ```
27
-
28
- </CodeGroup >
29
26
30
- The preceding example uses a WebSocket echo server, which you can run with the following command:
27
+ ws .onclose = () => {
28
+ console .log (' WebSocket connection closed!' );
29
+ }
31
30
32
- <CodeGroup >
33
-
34
- ``` bash
35
- $ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server
31
+ ws .onopen = () => {
32
+ ws .send (JSON .stringify ({ ' event' : ' SET_NAME' , ' new_name' : ` Croc ${ __VU } ` }));
33
+ }
34
+ ws .onerror = (err ) => {
35
+ console .log (err)
36
+ }
37
+ }
36
38
```
39
+
37
40
</CodeGroup >
Original file line number Diff line number Diff line change @@ -21,7 +21,12 @@ export default function () {
21
21
22
22
ws .onpong = () => {
23
23
console .log (' A pong happened!' );
24
+ ws .close ();
24
25
};
26
+
27
+ ws .onopen = () => {
28
+ ws .ping ();
29
+ }
25
30
}
26
31
```
27
32
You can’t perform that action at this time.
0 commit comments