> 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/2-wen-dang-docs/2.1-gai-lan/using_it_just_as_a_cross_browser_websocket.md).

# 2.1.111 作为跨浏览器使用websocket

如果您只想要WebSocket语义，那么您也可以这样做。 只需利用`send`和监听`message`事件：

## Serve(app.js)

```javascript
const io = require('socket.io')(80)
io.on('connection',(socket)=>{
    socket.on('message',()=>{})
    socket.on('disconnect',()=>{})
})
```

## Client(index.html)

```markup
<script>
    const socket=io('http://localhost/');
    socket.on('connect',()=>{
        socket.send('hi')
    })
    socket.on('message',(msg)=>{})
</script>
```

如果您不关心重新连接逻辑等，请查看`Engine.IO`，它是Socket.IO使用的WebSocket语义传输层。
