# Client-Server Communication

When JMap Pro opens, a connection to the associated JMap Server is established. This connection is used to direct the various system requests, including requests to load the project configuration and data as well as [extension requests](/jmapserversdk/jmap-pro-and-jmap-server-development/jmap-pro/jmap-pro-extensions.md#programming-extension-requests).

<figure><img src="/files/KG3Xwt3660xHHMY9n5Z1" alt=""><figcaption><p><em>Communication between JMap Pro application and JMap Server</em></p></figcaption></figure>

&#x20;Communication between a JMap Pro (desktop) application and JMap Server is done by exchanging requests and responses. The requests and the responses are in fact serialized objects that must normally be programmed, and these objects will contain the properties required to execute the request and return the information to the client. For example, an application managing citizen requests might have a request and response with the following properties:

| **Request**                                                                              | **Response**                                                                      |
| ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| Name of requesterType of requestDescriptionx and y coordinates of the request’s location | Status of the saved request in the database Unique identifier generated upon save |

For more information, refer to the [Programming Extension Requests](/jmapserversdk/jmap-pro-and-jmap-server-development/jmap-pro/jmap-pro-extensions.md#programming-extension-requests) section.

## Response status

Every response has a status that indicates if the request was executed successfully or if a problem occurred. The getStatus() method of the [*JMapExtensionResponse*](https://dev.k2geospatial.com/jmap/javadoc/Lima/com/kheops/jmap/net/JMapExtensionResponse.html) class allows you to get the status of the response. For the list of possible statuses and their description, refer to the documentation of the [*JMapExtensionResponse*](https://dev.k2geospatial.com/jmap/javadoc/Lima/com/kheops/jmap/net/JMapExtensionResponse.html) class.

Your extension should always check the status of a response before using it. If the status is not equal to JMapSRV\_STS\_SUCCESS, a special treatment should be done in order to manage the error situation. In this case, the getMessage() method allows you to generate a message explaining the cause of the error.

## Sending requests to JMap Server

The [*JMapSrvConnection*](https://dev.k2geospatial.com/jmap/javadoc/Lima/com/kheops/jmap/net/JMapSrvConnection.html) class is responsible for all communication between JMap client and JMap Server. The connection instance can be accessed using the JMap application context, as shown in the following example.

JMapSrvConnection jmapConn = JMapApplicationContext.getInstance().getConnection();

The following methods (inherited from the [*JMapNetworkConnection*](https://dev.k2geospatial.com/jmap/javadoc/Lima/com/kheops/jmap/net/JMapNetworkConnection.html) class) are used to send requests to JMap Server and to receive the responses.

<table data-header-hidden><thead><tr><th width="217"></th><th></th></tr></thead><tbody><tr><td><strong>Method</strong></td><td><strong>Description</strong></td></tr><tr><td><a href="https://dev.k2geospatial.com/jmap/javadoc/Lima/com/kheops/jmap/net/JMapNetworkConnection.html#executeRequest(com.kheops.jmap.net.JMapRequest)"><em>executeRequest()</em></a></td><td>Sends the request passed as a parameter to JMap Server and returns the response generated by JMap Server or by a server extension. This is a blocking method. It is well suited to situations where one must wait for the server’s response before continuing.</td></tr><tr><td><a href="https://dev.k2geospatial.com/jmap/javadoc/Lima/com/kheops/jmap/net/JMapNetworkConnection.html#pushRequest(com.kheops.jmap.net.JMapRequest)"><em>pushRequest()</em></a></td><td>Sends the request passed as a parameter to JMap Server. This method is non-blocking. When the response is received, the <a href="https://dev.k2geospatial.com/jmap/javadoc/Lima/com/kheops/jmap/net/JMapRequestClient.html#callback(com.kheops.jmap.net.JMapRequest,com.kheops.jmap.net.JMapResponse)"><em>callback()</em></a> method of the client of the request is called. This method is well suited to situations where one must quickly give back control to the user and when one can process the response in an asynchronous manner.</td></tr></tbody></table>

The following code example shows how to use the executeRequest method.

`MyRequest request = new MyRequest("This is a test", 555);`

`JMapSrvConnection jmapConn = JMapApplicationContext.getInstance().getConnection();`

`MyResponse response = (MyResponse)jmapConn.executeRequest(request); // Execution WILL block here`

`if (response.getStatus() == MyResponse.JMAPSRV_STS_SUCCESS)`

`{`

`// Do something useful with the response`

`}`

`else`

`{`

`// Handle error here`

`}`

The following code example shows how to use the *pushRequest* method.

`MyRequest request = new MyRequest("This is a test", 555);`

`request.setClient(new JMapRequestClient()`

`{`

`// Will be called when the response is received from JMapServer`

`@Override`

`public void callback(JMapRequest request, JMapResponse response)`

`{`

`if (response.getStatus() == MyResponse.JMAPSRV_STS_SUCCESS)`

`{`

`// Do something useful with the response`

`}`

`else`

`{`

`// Handle error here`

`}`

`}`

`});`

`JMapSrvConnection jmapConn = JMapApplicationContext.getInstance().getConnection(); jmapConn.pushRequest(request); // Execution WILL NOT block here`


---

# 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://docs-jmapserver-lima.k2geospatial.com/jmapserversdk/jmap-pro-and-jmap-server-development/jmap-pro/client-server-communication.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.
