---
description: TCP. compatible   80 / 443
---

# WebSocket

![](https://4116032991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgnugJ0SdX2tMAwP37V%2F-MEZUCV0Pn1qIEBQnDnc%2F-MEZgfAVfaKKpiDZRMcO%2Fimage.png?alt=media\&token=b6c9865f-1bd4-4d29-b911-1b54324f148d)

![](https://4116032991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgnugJ0SdX2tMAwP37V%2F-MEZUCV0Pn1qIEBQnDnc%2F-MEZggpDQM8WUaOUKXUA%2Fimage.png?alt=media\&token=12dccd9e-aad7-4427-98d3-68096f127619)



```
var ws = new WebSocket("wss://echo.websocket.org");

ws.onopen = function(evt) { 
  console.log("Connection open ..."); 
  ws.send("Hello WebSockets!");
};

ws.onmessage = function(evt) {
  console.log( "Received Message: " + evt.data);
  ws.close();
};

ws.onclose = function(evt) {
  console.log("Connection closed.");
};      
```

Client side example

```
var ws = new WebSocket("wss://echo.websocket.org");

ws.onopen = function(evt) { 
  console.log("Connection open ..."); 
  ws.send("Hello WebSockets!");
};

ws.onmessage = function(evt) {
  console.log( "Received Message: " + evt.data);
  ws.close();
};

ws.onclose = function(evt) {
  console.log("Connection closed.");
};      
```

#### &#x20;webSocket.readyState

#### webSocket.onopen

#### webSocket.onclose
