# 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语义传输层。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://socket.gitbook.io/docs/2-wen-dang-docs/2.1-gai-lan/using_it_just_as_a_cross_browser_websocket.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
