"Connection was forcibly closed by the remote host" when sending large amounts of data

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!

+3
5

, , Apple , , .

, .

0

" ", , , , , . FIN RST, .

, , , , ?

+4
+1

push-, , , ( ). socket.ReceiveFrom(), . ", " . -, .

As a result, I fixed my problem by adding a few WaitHandles to make the socket connection flow secure.

+1
source

Maybe you have too many open connections, and the server in the apple closes them for some reason. Try to find out if the problem persists with fewer connections.

+1
source

All Articles