1

I use the standard method of sending a file.

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;
    }

But there is one problem. If the file is large, more than 1.5 GB, then I get an error WSA_INVALID_PARAMETER - 87

How can I fix this and can I even do it or look for another option for sending the file?

4

1 回答 1

0

根据Windows 套接字错误代码

WSA_INVALID_PARAMETER 87 一个或多个参数无效。一个应用程序使用了一个 Windows Sockets 函数,该函数 > 直接映射到一个 Windows 函数。Windows > 功能表明一个或多个 > 参数存在问题。请注意,此错误是由 >操作系统返回的,因此错误编号可能会在 >未来的 Windows 版本中发生变化。

我们只能猜测可能的无效参数。我们应该是您使用完整文件路径。还要确保正确接收文件。要找到错误的根本原因,您必须捕获网络跟踪。首先通过添加配置条目启用跟踪并重现问题,您应该获得详细的跟踪文件。我们可以阅读它以了解根本原因

编辑:

网络跟踪中没有太多细节,所以我查看了Socket.SendFile实现的源代码。看起来调用只是去 WinSock TransmitFile并且这个 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();
                }
于 2017-06-25T12:04:57.313 回答