# Connect

```csharp
void Connect()
```

* **Description:**\
  The `Connect()` method is used to initiate the connection of the socket client to the specified server. This method attempts to connect to the server using the configured IP address and port. Once the connection is successful, the client can start sending and receiving messages. This method runs asynchronously, so it does not block the program while the connection is being established.
* **Parameters:**\
  This method does not take any parameters.
* **Returns:**\
  This method does not return any value. It simply starts the connection process.

***

**Functionality:**

When the `Connect()` method is called, the client attempts to establish a connection to the server. The `OnConnectionChanged` event is triggered **only if the connection is successful**.

* **For TCP clients:** The `Connect()` method tries to establish a reliable, connection-oriented communication channel. Once the connection is established, the client can start exchanging messages.
* **For UDP clients:** UDP is a connectionless protocol, but the `Connect()` method still prepares the client to send and receive messages. There is no formal session establishment like in TCP, and messages can be sent without waiting for a connection.

***

**Important Notes:**

* If the connection fails (for example, if the server is unreachable), the `IsConnected` property will return `false`.
* Ensure the client is properly configured (such as server IP and port) before calling the `Connect()` method.

***

**Usages:**

```csharp
socketClient.Connect();
```

The `Connect()` method starts the process of connecting the client to the server. Once the connection is successful, the client can begin message exchange.


---

# 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://tariksavas.gitbook.io/tarnet/docs/how-to-use/isocketclient/connect.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.
