473,322 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Socket appeasement

Kevinyy
77
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:
Expand|Select|Wrap|Line Numbers
  1. System.Net.Configuration.HttpWebRequestElement wr = new System.Net.Configuration.HttpWebRequestElement();
  2.             wr.UseUnsafeHeaderParsing = true;
  3.             try
  4.             {
  5.                 WebResponse response = (WebResponse)WebRequest.Create(url).GetResponse();
  6.                 Stream responsestream = response.GetResponseStream();
  7.  
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?
Sep 22 '08 #1
15 1385
Plater
7,872 Expert 4TB
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:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Sep 22 '08 #2
Kevinyy
77
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");
Expand|Select|Wrap|Line Numbers
  1. public void SError(Socket soket,int eNum, string eType, string eMessage)
  2.         {
  3.             SendMessage(soket, "HTTP/1.1" + " " + eNum + " " + eType + "\r\n");
  4.             SendMessage(soket, "Content-Type: text/plain" + "\r\n");
  5.             SendMessage(soket, "\r\n");
  6.             SendMessage(soket, eNum + " " + eType + "\r\n");
  7.             SendMessage(soket, eMessage + "\r\n");
  8.         }
  9. private void SendMessage(Socket soket, string sage)
  10.         {
  11.             Byte[] duff = new Byte[sage.Length];
  12.             Int32 SeMESSAGE = Encoding.ASCII.GetBytes(sage, 0, sage.Length, duff, 0);
  13.             try
  14.             {
  15.                 soket.Send(duff, SeMESSAGE, 0);
  16.             }
  17.             catch (Exception a)
  18.             {
  19.                 Console.WriteLine("Error: {0}", a.Message);
  20.             }
  21.         }
  22.  
I would like to send the message 403 and have the client browser stop working on the blocked request, how can i do so?
Sep 23 '08 #3
Plater
7,872 Expert 4TB
Well sending it the 403 error with correct header types, SHOULD have made it stop.
Try using the 404 error maybe?
Sep 23 '08 #4
Kevinyy
77
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?
Sep 23 '08 #5
Plater
7,872 Expert 4TB
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
Sep 23 '08 #6
Kevinyy
77
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
Sep 23 '08 #7
Kevinyy
77
No sucess...im using foxfire3, and when ever i request ex: sadkjsadsafj.com my program recognizes that it isnt a real address and sends:
Expand|Select|Wrap|Line Numbers
  1. private void SendMessage(Socket soket)
  2.  {
  3.             string sage="HTTP/1.0 404 File Not Found\n\r\n\r";
  4.             Byte[] fe = new Byte[0x400];
  5.             Int32 SeMessage = Encoding.ASCII.GetBytes(sage, 0, sage.Length, fe, 0);
  6.             try
  7.             {
  8.                 soket.Send(fe, SeMessage, 0);
  9.             }
  10.             catch (Exception a)
  11.             {
  12.                 Console.WriteLine("Error: {0}", a.Message);
  13.             }
  14. }
  15.  
but the browser just keeps waiting and waiting as if the page is going to load..
Sep 24 '08 #8
Plater
7,872 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. private void SendMessage(Socket soket)
  2.  {
  3.             string sage="HTTP/1.0 404 File Not Found\r\n\r\n";
  4.             byte[] payload = Encoding.ASCII.GetBytes(sage);
  5.             try
  6.             {
  7.                 soket.Send(payload);
  8.             }
  9.             catch (Exception a)
  10.             {
  11.                 Console.WriteLine("Error: {0}", a.Message);
  12.             }
  13. }
  14.  
Sep 24 '08 #9
Kevinyy
77
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:
Expand|Select|Wrap|Line Numbers
  1. private void SendMessage(Socket soket)
  2.  {
  3.             string sage="HTTP/1.0 404 File Not Found\r\n\r\n";
  4.             byte[] payload = Encoding.ASCII.GetBytes(sage);
  5.             s.Send(payload);
  6.             try
  7.             {
  8.                 soket.Send(payload);
  9.             }
  10.             catch (Exception a)
  11.             {
  12.                 Console.WriteLine("Error: {0}", a.Message);
  13.             }
  14. }
  15.  
how would i define "s"?
i just commented it out and now have this for testing:
Expand|Select|Wrap|Line Numbers
  1. public void SendMessage(Socket soket)
  2.         {
  3.             string sage = "HTTP/1.0 404 File Not Found\r\n\r\n";
  4.             byte[] payload = Encoding.ASCII.GetBytes(sage);
  5.                 //s.Send(payload);
  6.             try
  7.             {
  8.                 soket.Send(payload);
  9.             }
  10.             catch (Exception a)
  11.             {
  12.                 Console.WriteLine("Error: {0}", a.Message);
  13.             }
  14.         }
  15.  
and firefox still waits on this
Sep 24 '08 #10
Plater
7,872 Expert 4TB
s.Send(payload) was a typeo, and shouldn't have been in here.
Sep 24 '08 #11
Plater
7,872 Expert 4TB
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\nConnection: close\r\n\r\n";
Sep 24 '08 #12
Kevinyy
77
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\nConnection: 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?
Sep 24 '08 #13
Plater
7,872 Expert 4TB
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.
Sep 24 '08 #14
Kevinyy
77
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.
Sep 24 '08 #15
Kevinyy
77
Closing the socket works! - thank you :)
Sep 24 '08 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chuck E. Cheese | last post by:
I need a php page to connect to a python created socket and sent and receive data. below is the python code which opens a socket on the localhost @ port 21567: #!/usr/bin/python2 from socket...
8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
3
by: Thomas Hervé | last post by:
My problem is not really python specific but as I do my implementation in python I hope someone here can help me. I have two programs that talk through a socket. Here is the code : <server>...
4
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
4
by: O.B. | last post by:
I have a socket configured as TCP and running as a listener. When I close socket, it doesn't always free up the port immediately. Even when no connections have been made to it. So when I open...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.