I have a client that receives data over tcp and sends it over to another server. I'm trying to make sure that I don't lose any messages if any disconnect happens.
In the SendCallback
I check if the server was still connected. If the server got disconnected I want to save the message to a list to retry later.
Is there a way to get the string/byte array that failed to send?
private static void SendCallback(IAsyncResult ar)
{
try
{
Socket receiver = (Socket)ar.AsyncState;
int bytesSent = receiver.EndSend(ar);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
It's send call back but before you try to call this call back you try to fill your buffer . it's StateObject containing buffer size and socket handler and so on . So your answer definitely is YES. You should read more about asynchronous socket programming in MSDN reference Website.