Bytes sent but not receievd

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TedTrippin
    New Member
    • Nov 2008
    • 5

    Bytes sent but not receievd

    Hi,

    I need some ideas on where to start looking.

    I have a client/server app I'm testing. Most of the work is done in the client. The server simply waits for a command then immediately sends a response, the server is a stub.

    Both use the same NetworkStream for sending/receiving.

    The client has 2 threads; the main thread and a second thread with a stream.Read() which waits for server responses. Client sends the first command (BIND) and immediately gets a response. 15 seconds later client sends second command (HEARTBEAT) and immediately gets a response. 15 seconds later client again sends HEARTBEAT. I can see the server sending the response but can't see it being received by client.

    As there is nothing else going on and the client receives the first HEARTBEAT response what could possibly happen that stops it reading the second HEARTBEAT response?


    Heres the line that the client hangs on...
    Code:
      int bytesRead = networkStream.Read(buf, bufIndex, buf.Length - bufIndex);
    and heres the server that sends, receives
    Code:
    public void PduReceived(IPdu pdu)
    {
      log.Debug("*** Received " + pdu);
    
      IPdu response = ...;
      byte[] bs = response.GetBytes();
    
      log.Debug("Sending " + response + ", " + bs.Length + "bytes");
      stream.Write(bs, 0, bs.Length);
      stream.Flush();
    }
    The streams/sockets are not adjusted anywhere.
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    Question: You say the data isn't received. I've had problems with something like this in the past where it wasn't that the data wasn't received but that I was missing it.

    i.e.
    Data was sent
    Data should've been received
    I start listening

    Obviously this will never work. I had to adjust my application so that I started my listener thread which is used to process the incoming data and then fire off the data over the network stream. Only then could I receive.

    If you're doing the send and receive on the same thread, there's a strong possibility you could actually miss the incoming data rather than it never showing up. It showed up, but you weren't paying attention when it arrived.

    Not saying that is the issue, just throwing that thought out there...

    Comment

    • TedTrippin
      New Member
      • Nov 2008
      • 5

      #3
      Thanks for the reply.

      No, that isn't the problem. The client is a windows service and the server is a console app. The client receives the first 2 responses but not the third. I'm not messing with the threads/streams/sockets in between requests so I must have set something somewhere, but what?

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Is your listener getting hung up and missing the incoming data? What happens comment out the worker code and put a breakpoint on the receive? Do you get three responses then?

        Have you used a tool like WireShark to verify that the data is being received at the network card and that it's being sent to the correct address?

        If you can confirm that the data is sent to the right address and it's received by the network card at the hardware level then it's more likely your code. If it's not received at the hardware level and it was sent to the correct address then it's an issue somewhere on the network.

        Don't assume that's it's your code... don't assume it's not your code either though. I usually find that the easiest way to debug these issues is right from the ground up. Debug what we know...

        We know the data is being sent out by our service at the software (presentation) level.
        Do we know it's being dispatched at the hardware level? WireShark should confirm that the network card is dispatching it to the correct address.
        Do we know it's received at the hardware level at the destination? Again WireShark should confirm this.
        If it's not received correctly, do we know the data is being transmitted over the network to the correct address? Router logs near the destination should confirm this.
        Once we know that all this is present and correct, then we can assume there's an issue with our code... it could still be the network driver, but given that all your other network apps (presumably) are working correctly, this is unlikely.

        By the time we've gone through these steps, we should be able to determine if the issue is with the sender or the receiver and it will pinpoint where we will most likely be effective in debugging our code.

        Comment

        • TedTrippin
          New Member
          • Nov 2008
          • 5

          #5
          :(

          I've been a complete numpty! I had a try catch around the client Read() and it was not reporting the exception!!!!

          I had thought the problem was with the server cus that's what I was working on.

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            LOL - it pays to have an open mind when it comes to debugging. Things aren't always as they first appear.

            Glad you fixed it.

            Comment

            Working...