---
title: The State Machine in Detail
slug: ps/help/en_us/vtm/tsg/the-state-machine-in-detail
docTags: 
createdAt: 2026-08-02T09:41:21.278Z
---

::Image[]{src="https://api.archbee.com/api/optimize/wxZG1KsS4xNkVZYoiu_o9/M_zz1xSalBv3ksAd50ctn_processrules.png" position="flex-start" size="80" width="1001" height="466" initialPath="images/process_rules.png" githubPath="TSG/ps-vtm-tscript/images/process_rules.png" showCaption="false" indent="1"}

### Controlling the State Machine

The following TrafficScript functions can be used to control the state machine when processing requests and responses:

| Function                                                  | Notes                                                                                                                                                                                                                                                                                                                            |
| --------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <br />`pool.use()`                                        | When used in a request rule, aborts all rules processing and specify the pool to give the request to.                                                                                                                                                                                                                            |
| <br />`request.sendResponse()`<br />`http.sendResponse()` | When used in a request rule, specifies the response to send to the client. The current request is discarded and no data is sent to any back-end servers.<br />When the request rules finish, the response rules are run on the provided response.                                                                                |
| <br />`response.close()`                                  | In a response rule, close the connection to the server.<br />When the response rules complete, pending response data is sent to the client and the Traffic Manager then waits for a new request from the client.                                                                                                                 |
| <br />`request.endsAt()`<br />`request.endsWith()`        | In a request rule, use these functions to extract individual requests from the incoming data stream and process them synchronously in a request-response manner.<br />For some protocols, a client might send several requests in one go. These functions can be used to process the requests one-by-one.                        |
| <br />`request.retry()`                                   | In a response rule, retry the request if possible.<br />All request data that was read before and during a request rule is cached. A request can be retried if all the request data was read and cached; it can't be retried if data was subsequently streamed between the client and the server before a response was received. |
| <br />`response.flush()`                                  | In a response rule, flush the current response data. Use response.get() or response.getLine() to read further response data.<br />This function can be used to manually stream data from the server to the client, ensuring that the response rule does not complete until the response has completed.                           |
| <br />`connection.close()`<br />`connection.discard()`    | These functions can be used to abort a connection, optionally providing a response. The abort is immediate - no further rules are run at either the request or response stage.                                                                                                                                                   |
