---
schema_version: "1"
id: cae08673acf696bb998529f23ac4e3d81277bd47a2df3a610d87671bcc66d14e
title: WebSockets Connection Close
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/websockets-connector/latest/websockets-connector-connection-close.md
canonical_url: https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-connection-close
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e472746b3ae7a682012d6cbdbc0803b0c67ca214b7b2cea91bc0222c4c736ff1
description: MuleSoft Documentation Site
release: "1.0"
latest: true
---
---
product: WebSockets Connector
version: 1.0
is-latest-version: true
---

# WebSockets Connection Close

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

This operation closes currently connected WebSockets referenced by a Socket ID.

```xml
<flow name="closeConnection">
    <websocket:close-socket
        socketId="#[attributes.socketId]"
        reason="Quota exceeded"/>
</flow>
```

## Close Output

This operation returns no payload or attributes.

## On Socket Closed

A message source triggers a flow each time a WebSocket is closed. This is useful to perform cleanup
operations, logging, or updating the app’s state.

This is asynchronous. By the time the flow is invoked the socket has already been closed. Trying to
send messages through the referenced WebSocket results in an error.

```xml
<flow name="onConnectionClosed">
    <websocket:on-connection-closed path="/chat/*" config-ref="ws" />
    <logger
        level="INFO"
        message="No more messages please: you shall not pass." />
</flow>

<flow name="receiveMessagesFlow">
    <websocket:on-inbound-connection path="/chat" config-ref="ws" />
    <logger
        level="INFO"
        message="Someone just sent a message and now I will close this connection!" />

    <websocket:close-socket
        socketId="#[attributes.socketId]"
        reason="I don't like to talk."
        config-ref="ws" />
</flow>
```

The path parameter indicates the path of sockets that when closed, trigger the flow. To indicate
`catch-all`, you can use the asterisk wildcard symbol (∗).

## On Socket Closed Output

This operation returns an empty payload and a WebSocketAttributes object in the attributes.

## See Also

- [Salesforce Help](https://help.salesforce.com)

- [Reconnection](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-reconnection)

- [Server Components](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-server-components)

- [WebSockets Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/)
