Socket appeasement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kevinyy
    New Member
    • Jul 2008
    • 77

    Socket appeasement

    Ok so if i want to block any url's that include ex: "http://ad." from being sent via socket once requested by a client application. once i block that AD request from being sent out, do i have to send a socket of identical size(identical sizeof the AD) so the client doesnt keep asking for it? or how to i take care of that?

    I am requesting pages for the client like this:
    Code:
    System.Net.Configuration.HttpWebRequestElement wr = new System.Net.Configuration.HttpWebRequestElement();
                wr.UseUnsafeHeaderParsing = true;
                try
                {
                    WebResponse response = (WebResponse)WebRequest.Create(url).GetResponse();
                    Stream responsestream = response.GetResponseStream();
    Or, if the request from the client is an invalid request(cannot be resolved) how to i make the browser stop waiting for me to reply a response?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Could you reply back with the client with the correct HTTP headers/response?
    Something like 404 Not found or 403 Forbidden or 408 Request Timeout


    For more possibilities:

    Comment

    • Kevinyy
      New Member
      • Jul 2008
      • 77

      #3
      Just that doesnt do it, it the client browser still thinks there is more coming so it waits...
      here is the code format i use to send the 40x error:

      sent with: SError (soket, 403, "Forbidden" , "AD");
      Code:
      public void SError(Socket soket,int eNum, string eType, string eMessage)
              {
                  SendMessage(soket, "HTTP/1.1" + " " + eNum + " " + eType + "\r\n");
                  SendMessage(soket, "Content-Type: text/plain" + "\r\n");
                  SendMessage(soket, "\r\n");
                  SendMessage(soket, eNum + " " + eType + "\r\n");
                  SendMessage(soket, eMessage + "\r\n");
              }
      private void SendMessage(Socket soket, string sage)
              {
                  Byte[] duff = new Byte[sage.Length];
                  Int32 SeMESSAGE = Encoding.ASCII.GetBytes(sage, 0, sage.Length, duff, 0);
                  try
                  {
                      soket.Send(duff, SeMESSAGE, 0);
                  }
                  catch (Exception a)
                  {
                      Console.WriteLine("Error: {0}", a.Message);
                  }
              }
      I would like to send the message 403 and have the client browser stop working on the blocked request, how can i do so?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well sending it the 403 error with correct header types, SHOULD have made it stop.
        Try using the 404 error maybe?

        Comment

        • Kevinyy
          New Member
          • Jul 2008
          • 77

          #5
          Originally posted by Plater
          Well sending it the 403 error with correct header types, SHOULD have made it stop.
          Try using the 404 error maybe?
          ive tried both, is my header format correct?

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            You should be able to return this:
            "HTTP/1.0 404 Not Found\r\n\r\n"

            Comment

            • Kevinyy
              New Member
              • Jul 2008
              • 77

              #7
              Originally posted by Plater
              You should be able to return this:
              "HTTP/1.0 404 Not Found\r\n\r\n"

              http://www.w3.org/Protocols/HTTP/1.0/spec.html#Response
              Alright, ill try that and let you know; Thanks

              Comment

              • Kevinyy
                New Member
                • Jul 2008
                • 77

                #8
                No sucess...im using foxfire3, and when ever i request ex: sadkjsadsafj.co m my program recognizes that it isnt a real address and sends:
                Code:
                private void SendMessage(Socket soket)
                 {
                            string sage="HTTP/1.0 404 File Not Found\n\r\n\r";
                            Byte[] fe = new Byte[0x400];
                            Int32 SeMessage = Encoding.ASCII.GetBytes(sage, 0, sage.Length, fe, 0);
                            try
                            {
                                soket.Send(fe, SeMessage, 0);
                            }
                            catch (Exception a)
                            {
                                Console.WriteLine("Error: {0}", a.Message);
                            }
                }
                but the browser just keeps waiting and waiting as if the page is going to load..

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  the \r needs to come first.
                  I also don't understand your socket code. What is all that buisness you are doing there?

                  I woulda just done this:
                  Code:
                  private void SendMessage(Socket soket)
                   {
                              string sage="HTTP/1.0 404 File Not Found\r\n\r\n";
                              byte[] payload = Encoding.ASCII.GetBytes(sage);
                              try
                              {
                                  soket.Send(payload);
                              }
                              catch (Exception a)
                              {
                                  Console.WriteLine("Error: {0}", a.Message);
                              }
                  }

                  Comment

                  • Kevinyy
                    New Member
                    • Jul 2008
                    • 77

                    #10
                    Originally posted by Plater
                    the \r needs to come first.
                    I also don't understand your socket code. What is all that buisness you are doing there?

                    I woulda just done this:
                    Code:
                    private void SendMessage(Socket soket)
                     {
                                string sage="HTTP/1.0 404 File Not Found\r\n\r\n";
                                byte[] payload = Encoding.ASCII.GetBytes(sage);
                                s.Send(payload);
                                try
                                {
                                    soket.Send(payload);
                                }
                                catch (Exception a)
                                {
                                    Console.WriteLine("Error: {0}", a.Message);
                                }
                    }
                    how would i define "s"?
                    i just commented it out and now have this for testing:
                    Code:
                    public void SendMessage(Socket soket)
                            {
                                string sage = "HTTP/1.0 404 File Not Found\r\n\r\n";
                                byte[] payload = Encoding.ASCII.GetBytes(sage);
                                    //s.Send(payload);
                                try
                                {
                                    soket.Send(payload);
                                }
                                catch (Exception a)
                                {
                                    Console.WriteLine("Error: {0}", a.Message);
                                }
                            }
                    and firefox still waits on this

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #11
                      s.Send(payload) was a typeo, and shouldn't have been in here.

                      Comment

                      • Plater
                        Recognized Expert Expert
                        • Apr 2007
                        • 7872

                        #12
                        Have you used firebug in FF to see what is going on?
                        FF should be standards compliant and close itself.

                        You could try ammending the message to this:
                        string sage = "HTTP/1.0 404 File Not Found\r\nConnec tion: close\r\n\r\n";

                        Comment

                        • Kevinyy
                          New Member
                          • Jul 2008
                          • 77

                          #13
                          Originally posted by Plater
                          Have you used firebug in FF to see what is going on?
                          FF should be standards compliant and close itself.

                          You could try ammending the message to this:
                          string sage = "HTTP/1.0 404 File Not Found\r\nConnec tion: close\r\n\r\n";
                          firebug is for html type. but i tried it anyways :)
                          ok well now when my program cant resolve the address it sends that amended string and firefox doesnt wait anymore!
                          we are making progress!

                          But... when i block the ad's and manually send the same amended 404; firefox continues to wait. why doesnt it work here?

                          Comment

                          • Plater
                            Recognized Expert Expert
                            • Apr 2007
                            • 7872

                            #14
                            Well, you could also CLOSE the socket, that would also get FF to stop waiting.

                            also, firebug does like everything.
                            it will tell you every request/response made for the page.
                            so if you load a page with 4 pictures and one linked CSS file, it will show you all the requests/responses for those 4 pictures and the css file.

                            Comment

                            • Kevinyy
                              New Member
                              • Jul 2008
                              • 77

                              #15
                              i was hoping for a way to accomplish this without closing the socket (althought the way i coded my programming closing the socket wouldnt be a big deal- i dont think)
                              I'll give it a try, and also play around with firebug some more.

                              Comment

                              Working...