sockets and http question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Evanchik

    sockets and http question

    im having a small bug now where if i give a http header GET / with a
    connection: keep-alive i cant tell when the server is done sending. If i say
    connection: close i dont have a problem. Here is breifly my code.

    remember this works fine if i say Connection: close in the http header, if i
    say keepalive it does not. anyone know why?

    asynch send
    ------------------------
    client.BeginSen d(byteData, 0, byteData.Length , 0, new
    AsyncCallback(S endCallback), client);


    receive event
    --------------
    int bytesRead = client.EndRecei ve(ar);
    if (bytesRead > 0)
    {
    //more packets
    state.sb.Append (Encoding.ASCII .GetString(stat e.buffer,0,byte sRead));
    client.BeginRec eive(state.buff er,0,StateObjec t.BufferSize,0, new
    AsyncCallback(R eceiveCallback) , state);
    }
    else
    {
    if (state.sb.Lengt h > 1)
    { //its done
    response = state.sb.ToStri ng();
    receiveDone.Set ();
    }
    }
  • Joerg Jooss

    #2
    Re: sockets and http question

    Michael Evanchik wrote:
    [color=blue]
    > im having a small bug now where if i give a http header GET / with a
    > connection: keep-alive i cant tell when the server is done sending.
    > If i say connection: close i dont have a problem. Here is breifly my
    > code.
    >
    > remember this works fine if i say Connection: close in the http
    > header, if i say keepalive it does not. anyone know why?[/color]
    [snip]

    Question: Why are you using TcpClient instead of WebRequest? This means
    you must also implement all low-level TCP connection handling
    faithfully according to the HTTP spec, which might be the problem here.

    Cheers,
    --

    mailto:news-reply@joergjoos s.de

    Comment

    • Michael Evanchik

      #3
      Re: sockets and http question

      im not using either im using system.net sockets lowest level the framework
      will let me

      "Joerg Jooss" wrote:
      [color=blue]
      > Michael Evanchik wrote:
      >[color=green]
      > > im having a small bug now where if i give a http header GET / with a
      > > connection: keep-alive i cant tell when the server is done sending.
      > > If i say connection: close i dont have a problem. Here is breifly my
      > > code.
      > >
      > > remember this works fine if i say Connection: close in the http
      > > header, if i say keepalive it does not. anyone know why?[/color]
      > [snip]
      >
      > Question: Why are you using TcpClient instead of WebRequest? This means
      > you must also implement all low-level TCP connection handling
      > faithfully according to the HTTP spec, which might be the problem here.
      >
      > Cheers,
      > --
      > http://www.joergjooss.de
      > mailto:news-reply@joergjoos s.de
      >[/color]

      Comment

      • Michael Evanchik

        #4
        Re: sockets and http question

        how about why not? i have microsofts pre made object but was having trouble
        with cookies etc see


        also my question kind of got answered here



        what do you think?



        "Joerg Jooss" wrote:
        [color=blue]
        > Michael Evanchik wrote:
        >[color=green]
        > > im not using either im using system.net sockets lowest level the
        > > framework will let me[/color]
        >
        > Ah, guessed wrong ;-)
        >
        > The question remains, though -- why?
        >
        > Cheers,
        > --
        > http://www.joergjooss.de
        > mailto:news-reply@joergjoos s.de
        >[/color]

        Comment

        • Joerg Jooss

          #5
          Re: sockets and http question

          Michael Evanchik wrote:
          [color=blue]
          > how about why not? i have microsofts pre made object but was having
          > trouble with cookies etc see
          > http://www.microsoft.com/communities...fault.aspx?que
          > ry=httpwebrespo nse+evanchik&dg =&cat=en_US_850 c4b7a-113f-45f2-93ff-9d21
          > e03b29f3&lang=e n&cr=&pt=&catli st=&dglist=&ptl ist=&exp=&sloc= en-us[/color]

          OK, now I do remember that thread ;-)

          But what about the code I posted? No good?

          [color=blue]
          > also my question kind of got answered here
          > http://www.experts-exchange.com/Prog...Languages/C_Sh
          > arp/Q_21437151.html #14090121
          >
          > what do you think?[/color]

          That this doesn't answer anything. And that this is only shows the
          complexity of what you need to deal with if you try this stuff at
          socket level.

          Cheers,
          --

          mailto:news-reply@joergjoos s.de

          Comment

          Working...