我使用发送文件的标准方法。
internal bool SendToServer(string filename)
{
if (null == _netSocket || !_netSocket.Connected) CreateSocketConnect();
try
{
_netSocket.SendFile(filename);
File.Delete(filename);
return true;
}
catch (SocketException ex)
{
CloseSocketConnect();
string error = string.Format("exception: {0} error code: {1} stacktrace: {2}", ex.Message, ex.ErrorCode, ex.StackTrace);
_twriter.AddMessage(string.Format("-> {0}", error));
Logger.Instance.WriteLine(ex.Message);
}
return false;
}
但有一个问题。如果文件很大,超过1.5 GB,那么我会收到错误 WSA_INVALID_PARAMETER - 87
我该如何解决这个问题,我是否可以这样做或寻找另一个发送文件的选项?
答案 0 :(得分:0)
WSA_INVALID_PARAMETER 87 一个或多个参数无效。 应用程序使用Windows套接字函数,该函数>直接映射到Windows函数。 Windows>功能指示一个或多个>参数的问题。请注意,>操作系统会返回此错误,因此错误编号可能会在>未来版本的Windows中发生更改。
我们只能猜出可能的无效参数。我们应该使用完整文件路径。还要确保receive the file correctly。要找到错误的根本原因,您必须捕获network trace。首先通过添加config entry启用跟踪并重现问题,您应该获得详细的跟踪文件。我们可以{{ 3}}根本原因
修改强>
网络跟踪中没有太多细节,所以我查看了read it to understand实现的源代码。这看起来就像电话一样 WinSock Socket.SendFile和这个TransmitFile抛出无效参数错误。所以这是一个winsock错误,这里是winsock PInvoke发生的
// This can throw ObjectDisposedException.
if (fileHandle != null ?
!UnsafeNclNativeMethods.OSSOCK.TransmitFile_Blocking(m_Handle.DangerousGetHandle(), fileHandle, 0, 0, SafeNativeOverlapped.Zero, asyncResult.TransmitFileBuffers, flags) :
!UnsafeNclNativeMethods.OSSOCK.TransmitFile_Blocking2(m_Handle.DangerousGetHandle(), IntPtr.Zero, 0, 0, SafeNativeOverlapped.Zero, asyncResult.TransmitFileBuffers, flags))
{
errorCode = (SocketError) Marshal.GetLastWin32Error();
}