Results 1 to 4 of 4

Thread: Help - Disable Nagle Algorithm in VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    2

    Help - Disable Nagle Algorithm in VB6

    I've read tons about whether or not to do it, but I can't find any documentation for VB6 or example code of someone who has actually done it. I've spent hours searching for the code. Now I'm convinced it can't be done in VB6, or at least I haven't found the right code. Here's what I've tried and the result.

    sockMain.NoDelay = True
    *Error: Throws an error that method or data member is not found and it highlights NoDelay.

    setsockopt sockMain.SocketHandle, SOL_SOCKET, TCP_NODELAY, OptVal, Len(OptVal)
    *OptVal is set to 1
    **Error: Variable not defined and highlights SOL_SOCKET

    Any help is appreciated.

  2. #2
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Help - Disable Nagle Algorithm in VB6

    Code:
    Private Const SOL_SOCKET As Long = &HFFFF&
    Private Const TCP_NODELAY As Long = &H1
    Private Declare Function getsockopt Lib "ws2_32" ( _
        ByVal s As Long, _
        ByVal level As Long, _
        ByVal optname As Long, _
        ByRef optval As Any, _
        ByRef optlen As Long _
        ) As Long
    Code:
        Dim TcpNoDelay As Long 'WIN32 BOOL
        getsockopt sockMain.SocketHandle, SOL_SOCKET, TCP_NODELAY, TcpNoDelay, LenB(TcpNoDelay)

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    2

    Re: Help - Disable Nagle Algorithm in VB6

    Code:
        Dim TcpNoDelay As Long 'WIN32 BOOL
        getsockopt sockMain.SocketHandle, SOL_SOCKET, TCP_NODELAY, TcpNoDelay, LenB(TcpNoDelay)
    [/QUOTE]

    Thank you for this code. It runs without error. I have two questions.

    1) You set the variable as "Long" rather than "Bool", is that for VB6 as opposed to VB.net, or is that for a specific version of windows. Second, I tried to test the code by sending many small packets at 10 and 100 ms and couldn't verify whether Nagle is deactivated, so can you help by confirming the correct value of TcpNoDelay. From your code, I would guess it should = 0, but I always think of 0 as the default (which is that Nagle is Active), which would mean TcpNoDelay = 1 is Nagle Inactivated. Please confirm.

    2) Why getsockopt and not setsockopt?

    Thanks,
    Ken
    Last edited by frostykdog; Feb 27th, 2018 at 03:38 PM.

  4. #4
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Help - Disable Nagle Algorithm in VB6

    1)
    in the windows SDK, BOOL is a typedef for int. An int is 32 bit (C/C++).
    TRUE is a 1
    FALSE is a 0

    in VB6 and VBA Boolean and Integer are 16 bit, Long is 32bit. See the manual for .NET types, as they are also different.
    in VB6 True is a -1 (16bit), and False is a 0 (16bit)
    This is because in VB there are no dedicated logical opperators like in C. VB actually uses bitwise operators instead.


    basically an SDK BOOL is not a VB6 Boolean.

    I typically do the following to explicitly differentiate between VB and API values

    Code:
    Enum API
        [True] = 1
        [False] = 0
        [Null] = 0
    End Enum

    2)
    getsockopt is to read the option, setsockopt is to set the option.

    you want setsockopt.

    Code:
    Private Declare Function setsockopt Lib "ws2_32" ( _
        ByVal s As Long, _
        ByVal level As Long, _
        ByVal optname As Long, _
        ByRef optval As Any, _
        ByVal optlen As Long _
        ) As Long
    
        Dim TcpNoDelay As Long
        TcpNoDelay = API.True
        setsockopt sockMain.SocketHandle, SOL_SOCKET, TCP_NODELAY, TcpNoDelay, LenB(TcpNoDelay)
    according to this --> https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    setting TCP_NODELAY to 1 "Disables the Nagle algorithm for send coalescing."

    edit:As for what's the default - On windows I don't know. that's what getsockopt should tell you

    On modern hardware and OS I don't know that you'll see any differences depending on what you set it to.
    Last edited by DEXWERX; Feb 27th, 2018 at 04:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width