我在一个C#多线程Windows服务中发送推送通知时遇到了一些问题。
当我向APNS发送大量通知时,一些线程会抛出异常:
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) ...
我有一个线程池,其中包含16个线程,每个线程都会打开一个到Apple的连接。 不是超时问题,因为我已经尝试使用
sslStream.WriteTimeout = 60000;
我还尝试了这个:Client.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.KeepAlive, false);
发送开始时连接未关闭。
编辑:我认为所有数据都已发送,但Apple突然关闭了连接。你有想法关于这个异常出现的原因吗? 该如何解决?
如果需要,我可以提供一些代码。
非常感谢您的回答!