Hello lakshmi,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are having SocketException while sending message to bot via connector client.
Regarding the error code, it happens due to many issues. The area to focus are not limited to the following, use the links to review for more steps to resolve them:
- SSL/TLS Issues, Service Updates, and Certificate Issues https://github.com/Azure/azure-functions-host/issues/8168 and https://learn.microsoft.com/en-us/answers/questions/789967/azure-function-outgoing-ssl-exceptions
- Network configuration, and retry logic implementation, https://github.com/Azure/azure-functions-durable-extension/issues/1069
- New connection for every request, might lead to port exhaustion, https://learn.microsoft.com/en-us/azure/azure-functions/functions-diagnostics and https://learn.microsoft.com/en-us/azure/azure-functions/manage-connections?tabs=csharp
With all of the above, you can create additional code to reuse HttpClient in your Azure Function, this will make sure that the HttpClient instance is reused to reduce the risk of port exhaustion. The below is a sample code snippet for your use:
public static class Function
{
private static readonly HttpClient httpClient = new HttpClient();
[FunctionName("Function")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
var response = await httpClient.GetAsync("https://example.com");
string responseBody = await response.Content.ReadAsStringAsync();
return new OkObjectResult(responseBody);
}
}
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.