I have some problems sending push notifications in a C # multi-threaded Windows service.
When I send a lot of APNS notifications, some threads throw an exception:
Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Security._SslStream.StartWriting(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.Write(Byte[] buffer) ...
I have a threadPool of 16 threads, and each thread opens a connection with Apple.
This is not a timeout because I tried with: sslStream.WriteTimeout = 60000;
I also tried:Client.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.KeepAlive, false);
The connection does not close at the start of sending.
EDIT: I think all data is sent, and Apple suddenly closes the connection.
Do you have any idea about the origin of this exception? How to solve this?
I can give you the code if necessary.
Thanks so much for your answers!