I have some troubles with the sending of push notifications in a C# multithread windows service.
When I send a lot of notifications to the APNS, some of threads throws 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 open a connexion to Apple.
It’s not a timeout because i have tried with : sslStream.WriteTimeout = 60000;
I have also tried with: Client.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.KeepAlive, false);
The connection is not closed at the beginning of the sending.
EDIT : I think that all data are sent, and Apple close the connection suddenly.
Have you an idea of the origin of this exception ?
How resolve it ?
I can give you some code if it’s needed.
Thanks a lot for your answers !
No solution, but I think that is Apple who close the connexion in order to reuse the socket, when no more data are sent.
To avoid errors, I use enhanced notifications now.