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?

Rohith
  • 5,527
  • 3
  • 27
  • 31
  • I'd suggest you to look for alternate option to send such files. Though strange why it throws `WSA_INVALID_PARAMETER` error. in this case, API says - 'One or more parameters are invalid.' What are you passing in filename, when you receive such errors? – Am_I_Helpful Jun 25 '17 at 10:46
  • Something like this zip_2098_23062017000737.zip.base64.response – Black raven Jun 25 '17 at 11:01
  • Is this a file name? If not, please share the relevant code. – Am_I_Helpful Jun 25 '17 at 11:07
  • Yes it real filename. – Black raven Jun 25 '17 at 11:25
  • I updated code in question – Black raven Jun 25 '17 at 11:36
  • Post the complete error message or exception's stack trace as well. – Am_I_Helpful Jun 25 '17 at 11:42
  • Exception: The parameter is set incorrectly error code: 87 stacktrace: in System.Net.Sockets.Socket.SendFile (String fileName, Byte [] preBuffer, Byte [] postBuffer, TransmitFileOptions flags)     In System.Net.Sockets.Socket.SendFile (String fileName)     In ARInvoker.Receiver.SendToServer (String filename) in c: \. Net \ ARClient \ ARInvoker \ Receiver.cs: line 94 – Black raven Jun 25 '17 at 12:36

1 Answers1

0

As per Windows Socket Error codes,

WSA_INVALID_PARAMETER 87 One or more parameters are invalid. An application used a Windows Sockets function which >directly maps to a Windows function. The Windows >function is indicating a problem with one or more >parameters. Note that this error is returned by the >operating system, so the error number may change in >future releases of Windows.

We can only guess the possible invalid parameter. We should be you using Full file path. Also make sure to receive the file correctly. To get to the root cause of the error,You have to capture a network trace .First enable the tracing by adding a config entry and reproduce the issue,you should get a detailed trace file.We can read it to understand root cause

Edit:

There is not much details in the network trace,so I looked at the source code of Socket.SendFile implementation . It looks like the call is simply going to WinSock TransmitFile and this TransmitFile is throwing the invalid parameter error .So this is a winsock error ,here's the winsock PInvoke happening

// 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();
                }
Rohith
  • 5,527
  • 3
  • 27
  • 31
  • Information: 0 : [6928] Socket#25702951 - Создано подключение с 10.200.3.77:12994 к 10.200.2.235:7118. Verbose: 0 : [6928] Exiting Socket#25702951::Connect() Verbose: 0 : [6928] Socket#25702951::SendFile() Error: 0 : [6928] Socket#25702951::UpdateStatusAfterSocketError() - 87 Error: 0 : [6928] Exception in Socket#25702951::SendFile - Параметр задан неверно. Verbose: 0 : [6928] Socket#25702951::Shutdown(SocketShutdown#2) – Black raven Jun 25 '17 at 12:31
  • As you might have noticed, this error only occurs if the file is larger than 1.5 GB – Black raven Jun 25 '17 at 12:33
  • As soon as we connect,it's disconnect.I was expecting to see hex data information.Timestamp also is immediate . Not showing any details: Information: 0: [6928] Socket # 25702951 - Created connection from 10.200.3.77:12994 to 10.200.2.235:7118. Verbose: 0: [6928] Exiting Socket # 25702951 :: Connect () Verbose: 0: [6928] Socket # 25702951 :: SendFile () Error: 0:. – Rohith Jun 25 '17 at 13:16
  • Error seems to be coming from winsock,added winsock tag to the question. – Rohith Jun 25 '17 at 17:33
  • How I can to do this? Add winsock tag to the question. – Black raven Jun 25 '17 at 20:40