C# Proxy connection closed unexpectedly

Monrox

Power Member
Joined
Apr 9, 2010
Messages
617
Reaction score
588
I am getting a lot of webexceptions (The underlying connections was closed: The connection was closed unexpectedly) when using a httpwebrequest to connect through proxies... and am out of ideas.

Anyne knows how to fix this? It's driving me crazy!

Thanks
 
usually when you see connection errors like this related to proxy servers it's due to the proxies timing out or otherwise dropping connection for an unspecified reason.

what kind of frequency are we talking here? and are you trying to connect over straight http protocol or SSL?

-edit-

could just be some dodgy, error prone proxies.
 
Well it's a simple httpwebrequest. When I try to chain proxies, the rate of this kind of exception is even 100%, even the working ones 'stop' working. This means something is wrong on my side or at least I think so.

Anyway, I decided to try my luck with sockets instead we'll see how that goes.

Hey smack, how would you join the buffers of Socket.Receive to get one big byte array? I am making a function to retrieve any resource and a string won't do without unneeded reconversion back to byte [].

Generics.AddRange is adding empty bytes if the buffer is not full.
 
It's all speculation until you post some code and error messages.
 
Well it's a simple httpwebrequest. When I try to chain proxies, the rate of this kind of exception is even 100%, even the working ones 'stop' working. This means something is wrong on my side or at least I think so.

Anyway, I decided to try my luck with sockets instead we'll see how that goes.

Hey smack, how would you join the buffers of Socket.Receive to get one big byte array? I am making a function to retrieve any resource and a string won't do without unneeded reconversion back to byte [].

Generics.AddRange is adding empty bytes if the buffer is not full.


ah ok i've never worked with daisy chaining proxies in the framework.

as far as the byte[] use an iterator loop (foreach)

i think this should do what you're asking. i haven't used this for sockets, it's original purpose was for reconstructing an encryption key stored in two places. (i know it's in vb, but same concept)

Code:
Dim tempkey() As Byte = {1, 2, 4,...}
Dim MyKey(31) As Byte
Dim i As Integer
  For Each Bitt As Byte In tempkey
    MyKey.SetValue(Bitt, i)
    i += 1
   Next

  For Each Bitt As Byte In KeyBytes
    MyKey.SetValue(Bitt, i)
    i += 1
  Next

since i knew the total length of the end byte[] prior to putting them together i was able to dimension the final array with an explicit value, you will probably have to resize it based on the size of the two arrays you're putting together.

now for the response of the request method in the sockets namespace it's actually getting setup with the return with the inData from the SocketState.

i know i'm probably rambling a bit at this point, it's quite early and i haven't had my requisite gallon of coffee yet, but hopefully this answers your questions.
 
Well it's a simple httpwebrequest. When I try to chain proxies, the rate of this kind of exception is even 100%, even the working ones 'stop' working. This means something is wrong on my side or at least I think so.

Anyway, I decided to try my luck with sockets instead we'll see how that goes.

Hey smack, how would you join the buffers of Socket.Receive to get one big byte array? I am making a function to retrieve any resource and a string won't do without unneeded reconversion back to byte [].

Generics.AddRange is adding empty bytes if the buffer is not full.



Here is code I've written to append byte arrays...



public static byte[] byteAppend(byte[] destination, byte[] src)
{
if (destination == null) destination = new byte[0];

byte[] newbytes = new byte[destination.Length + src.Length];
destination.CopyTo(newbytes, 0);

src.CopyTo(newbytes, destination.Length);

return newbytes;
}



sample usage :

byte[] a;
byte[] b = new byte[100];
byte[] c = new byte[200];
byte[] d = new byte[300];

a=(a,b);
a=(a,c);
a=(a,d);

or
a = (b,c);
a = (a, d);

.....

hope that doesn't confuse :)
 
Back
Top