Announcement

Collapse
No announcement yet.

Very strange TCP OPEN behavior

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Very strange TCP OPEN behavior

    I have an application written in PBDLL 6.
    It is a multithreaded application.
    When the application starts, it sets up a couple of
    listening ports. Other machines can connect and disconnect
    all day long without any trouble and send/rcv data.
    I also have a timer that fires about every 5 minutes.
    This event creates a new thread which reads a couple of
    values from the registry, an IP Address and Port, an then
    attempts to connect to that IP and Port.
    That is where it goes wrong.
    As soon as the TCP OPEN statement is reached, the CPU spikes
    to 100% and all of the other TCP connections appear to stop.
    Each connection is ran and maintained on its own thread. However,
    because the TCP OPEN is consuming all of the CPU, none of the
    other threads can process. If the machine that the timer thread
    is trying to connect to does not exist, it was turned off, then
    it will sit for about 30 seconds at 100% CPU until the TCP OPEN
    returns with an error 57.
    I have tried using the timer with a callback and a window mesage.
    All the timer event does is THREAD CREATE.
    I have stepped through the code and place numerous print to file
    statements along with GetTickCount().
    Every thing works fine UP TO the TCP OPEN and AFTER the TCP
    open. It is ONLY when executing the TCP OPEN that this happens.
    Any other TCP OPEN statements work just fine. Only when in this
    timer event.

    Does anyone have a clue why this would be?

    Thanks
    Ben Clark


    ------------------
    Ben Clark
    [email protected]
    If at first you don't succeed, destroy all evidence that you tried.

  • #2
    57, hmmm
    Either it cannot open and it spikes until it times out (IE Does that a lot sometimes), or is there a chance it is trying to open a port that it is listening to on the SAME computer? Ie connecting to itself?

    Test it to an atomic clock when in doubt, you will always get a quick return, if it still happens then you can look at the thread code....

    Got a sample code?

    ------------------
    Scott Turchin
    MCSE, MCP+I
    Computer Creations Software
    http://www.tngbbs.com/ccs
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      It is connecting to the correct machine.
      If I turn on the machine it will connect.
      The CPU will still spike but only for an instant.
      It is when the machine is not there that the CPU stays
      at 100% until the error 57.

      This causes a problem because other machines are in the process
      of sending and receiving packets. All of these connections
      stop until the error 57 or a successfull connection.


      ------------------
      Ben Clark
      [email protected]
      If at first you don't succeed, destroy all evidence that you tried.

      Comment


      • #4
        What TIMEOUT value are you using in the TCP OPEN statement? Although the documentation says the timeout is measured in milliseconds, the value should be specified in seconds (fractional seconds are not supported, so "TIMEOUT .2" is equivalent to "TIMEOUT 0").

        If this does not help, can you show us the portion of the code that fires the TCP OPEN ?

        BTW, anyone know off-hand where Windows stores the "default" timeout for Winsock operations? (ie, TCP OPEN with no timeout value specified)

        On some computers (ie, mine) it seems to be 60 seconds, others seem to wait much longer (infinite?) -- Thanks!


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          The code is:

          ID = NewConnection()

          ' Get a new handle
          hCon(ID).hSock = FREEFILE

          PortNum = 20021
          IpAddress = MFI_CPU

          ' Attempt to connect to the client
          TCP OPEN PORT PortNum AT IpAddress AS hCon(ID).hSock TIMEOUT 2
          ' Did it work?
          IF ERR THEN
          ' Error OOPS
          HandleError ERR, "Client Connection", "Error while attempting to connect to " + TRIM$(IpAddress) + " on Port " + FORMAT$(PortNum) + ". " + GetErrorDescription(ERR)
          ' Clear this entry so it can be used again
          hCon(ID).hSock = 0
          FUNCTION = 0
          EXIT FUNCTION
          END IF

          Remember, if the machine is running and listening for a connection,
          everything works fine.
          It is when the machine is not there that the problem occurs.


          ------------------
          Ben Clark
          [email protected]
          If at first you don't succeed, destroy all evidence that you tried.

          Comment


          • #6
            I can reproduce that with ICQ, Outlook, MSIE, Eudora etc....
            WIndows has a tendency to lock up momentarily (TCP lockup anyway) until the timeout occurs...

            You will experience this, in some occasions you may also expierence your screen going white and not recovering....depends on teh OS of course, 98 will do that from time to time...
            I saw this issue a LOT...

            But, sufficies to say, check your NIC drivers, do all that normal stuff you would do if it only occurs on ONE machine when the other is off...

            But test on another machine, still occur? Winsock....and OS, and I do not think you can get around that.
            Your app will have to do the error handling....


            ------------------
            Scott Turchin
            MCSE, MCP+I
            Computer Creations Software
            http://www.tngbbs.com/ccs
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment

            Working...
            X