> For the complete documentation index, see [llms.txt](https://socket.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://socket.gitbook.io/docs/3-ke-hu-duan-apiclientapi/3.1-io/initialization_examples_with_websockets_transport_only.md).

# 3.1.8 初始化示例-仅限websocket传输

默认情况下，首先建立一个长轮询连接，然后升级到“更好”的传输（如WebSocket）。如果你喜欢危险的操作，这部分可以跳过：

```javascript
const socket=io({
    transports:["websocket"]
})

// 重新连接时，将传输选项重置为websocket
// 连接可能失败（由代理、防火墙、浏览器等引起）
socket.on('reconnect_attempt',()=>{
    socket.io.opts.transports=['polling','websocket']
})
```
