Problem: The underlying connection was closed: Unable to connectto the remote server

K

Kristof Thys

Hello,

I'm developing a C# - windows forms application. To get some information
for my application, I'm connecting to an URL, wich gives me XML
generated using php.
With 90% of the users, this code just works fine:

Code:
WebRequest request = WebRequest.Create(URL);

try
{
request.Timeout = 50000;
WebResponse response = request.GetResponse();
}
catch(Exception ex)
{
WriteToLog(LogType.Info,ex.Message.ToString());
response = null;
}

But with some users, I get an exception saying: The underlying
connection was closed: Unable to connect to the remote server

I'm sure that there is no firewall on, and I've asked the user to
disable any proxy settings...

Is there something that I'm overseeing or that can be improved to this code?


thanks in advance,

Kristof
 
A

at

This can happen when the request lacks something like for example a cookie.
Are there other ways in which you can connect? If so, have a look with
ethereal what goes over the wire. That sometimes gives the required
information.
 
L

Landi

Kristof,
Your code is fine. It's the URL that you are connecting to that is making
your code throw an exception. I am assuming this is your server that is
giving you the XML; if so then I would make sure that the server is working
properly and that it's never loosing connection.
 
M

Mezzrow

Yep.
When writing these types of apps its important to not presume that the
URL will be available. Its good practice to also double check the
formatting of the XML, but that's not what's happening here.
 
K

Kristof Thys

Mezzrow said:
Yep.
When writing these types of apps its important to not presume that the
URL will be available. Its good practice to also double check the
formatting of the XML, but that's not what's happening here.

The strange thing is, that with 19 of the 20 testusers, it is working
just fine. But with one user, it keeps on giving this error...
I believe it must be some kind of setting but I kind find out wich one...
It isn't the firewall, he doesn't have a proxyserver set, and the server
works fine, because at the same moment I'm able to connect...

So I'm really stuck...
 
K

Kristof Thys

I'm not that familiar with ethereal, but I tried installing it (and
wincap3.1) on my pc... But when I run my program, it doesn't seem to
catpure anything...
I don't have to run it on the server pc do I?

There is always the problem to make a program like this run on someone
elses pc, especially when he's living in Romania...

thx for you help
 
A

at

Run ethereal, select Capture/Start from the menu, select an interface (you
see the drop down on top of the ethereal screen?) (I always choose my
netcard to catch anything) and click ok. That is what I do and here it
works. When I click stop it displays what it caught (if anything, you can
test by browsisng to some page somewhere). Client/server side doesn't
matter.

Any luck?
 
K

Kristof Thys

at said:
Run ethereal, select Capture/Start from the menu, select an interface (you
see the drop down on top of the ethereal screen?) (I always choose my
netcard to catch anything) and click ok. That is what I do and here it
works. When I click stop it displays what it caught (if anything, you can
test by browsisng to some page somewhere). Client/server side doesn't
matter.

Any luck?
Ok, on my pc this works fine... I see two relevant things, one GET /URL
HTTP/1.1
and one return: HTTP/1.1 200 OK[Unreassembled Packet] with 50 packets or
so following from the same source and with the same destination saying:
Continuation or non-HTTP traffic...

I will try and do the same with the person where it doesn't work, and
I'll let you know the outcome...

Thanks for your cooperation
 
A

at

Please note that you can save the captured packets (just use the default
format) so you can compare later on.

In the end you should find a difference somewhere between the captured
packets. That should give you a hint on what is wrong.

Kristof Thys said:
at said:
Run ethereal, select Capture/Start from the menu, select an interface
(you see the drop down on top of the ethereal screen?) (I always choose
my netcard to catch anything) and click ok. That is what I do and here it
works. When I click stop it displays what it caught (if anything, you can
test by browsisng to some page somewhere). Client/server side doesn't
matter.

Any luck?
Ok, on my pc this works fine... I see two relevant things, one GET /URL
HTTP/1.1
and one return: HTTP/1.1 200 OK[Unreassembled Packet] with 50 packets or
so following from the same source and with the same destination saying:
Continuation or non-HTTP traffic...

I will try and do the same with the person where it doesn't work, and I'll
let you know the outcome...

Thanks for your cooperation
 
L

Landi

You are not going to catch anything with Ethereal. He is not having any
communication with the server at all and that is why his code is throwing an
exception. Even if there is anything showing up on the log he probably wont
know what to look for.
 
A

at

Very constructive...not.

Some clients work, another one does not. What is the difference between the
packets being send from the working clients and the one that does not work?

At least I am interested to know.

Landi said:
You are not going to catch anything with Ethereal. He is not having any
communication with the server at all and that is why his code is throwing
an
exception. Even if there is anything showing up on the log he probably
wont
know what to look for.
--
(e-mail address removed)
http://dowhileloop.com website development
http://publicjoe.dowhileloop.com -- C# Tutorials

Kristof Thys said:
Hello,

I'm developing a C# - windows forms application. To get some information
for my application, I'm connecting to an URL, wich gives me XML
generated using php.
With 90% of the users, this code just works fine:

Code:
WebRequest request = WebRequest.Create(URL);

try
{
request.Timeout = 50000;
WebResponse response = request.GetResponse();
}
catch(Exception ex)
{
WriteToLog(LogType.Info,ex.Message.ToString());
response = null;
}

But with some users, I get an exception saying: The underlying
connection was closed: Unable to connect to the remote server

I'm sure that there is no firewall on, and I've asked the user to
disable any proxy settings...

Is there something that I'm overseeing or that can be improved to this code?


thanks in advance,

Kristof
 
K

Kristof Thys

Landi said:
You are not going to catch anything with Ethereal. He is not having any
communication with the server at all and that is why his code is throwing an
exception. Even if there is anything showing up on the log he probably wont
know what to look for.

The question remains, why isn't there any communication?
It is possible to use a browser, IE or any other, to go to the URL from
the pc where the program throws an exception at the exact same moment...
So it seems to me, the server is just doing fine, but the client pc is
blocking the request/response for an unknown reason...
 
A

at

What is the url? String, uri?

What do you get in s?

string s;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
response.Close();
}
catch(Exception ex)
{
s = ex.ToString();
WriteToLog(LogType.Info, s);
}
response = null;
 
K

Kristof Thys

at said:
What is the url? String, uri?

What do you get in s?

string s;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
response.Close();
}
catch(Exception ex)
{
s = ex.ToString();
WriteToLog(LogType.Info, s);
}
response = null;
The url is
http://beta.soccerproject.com/man_tool.php?login=OscarCookie&pw=newsgroup

The exception I'm getting is "The underlying connection was closed:
Unable to connect to the remote server."
And right after that: System.NullReferenceException: Object reference
not set to an instance of an object.
I don't see where the second exception comes from...

The exact code is this:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response=null;
try
{
response = (HttpWebResponse)request.GetResponse();
response.Close();
}
catch(Exception ex)
{
WriteToLog(LogType.Info, ex.ToString());
}

if(response == null)
{
CGlobals.WriteToLog(LogType.Info,"Response = NULL");
//He's not coming here...
timeOut = true;
}

XHTML = "";
if(!timeOut)
{
StreamReader reader = new treamReader(response.GetResponseStream());
XHTML = reader.ReadToEnd();
}


BTW: Thanks for your patient help...
 
A

at

If you use ethereal on the serverside and run a working client, do you see
any cookie stuff in the received http headers? It looks to me the client
that does not work does not send cookie. It is my assumption that a cookie
should be passed as part of the request.

If you are unable to sit behind the server, check cookie settings on the
client.

Or, use I.E. from the failing client and see what headers get send.
 
K

Kristof Thys

I don't own the server, so running ethereal there is a problem...
Running ethereal on the failing client isn't easy neither, because the
failing client situates in Romania, while I'm from Belgium...

But when I try to change my IE settings, and block all cookies,
everything keeps working... Even browsing to the url with IE...

Tricky problem :S
 
A

at

That makes it rather difficult! But...

Can you have the client person in Romania use a http logging proxy? So that
you can get at the headers being send? Do you run a client yourself as well
by the way? Do you get the headers it sends?
 
K

Kristof Thys

I'm sorry for my stupidity, but I don't know exactly what you are
talking about... I'm not using a http logging proxy, but where can I
download something like that and how can I use it? What does it do exactly?

thx
 
A

at

A proxy forwards requests and responses between client and server. In the
process it can save a copy of what is being send including the headers.

Client normally connect to port 80 (HTPP). When a proxy is started it
listens on another port so the client has to connect to that other port for
web access. The proxy than forwards to the target on port 80 and vice versa.
It is like a bridge. On the bridge there is a person seeing all who pass.

There are several proxies available for download on the web. Just get some
and see if you can get then running on your own machine. Once you have found
one you like (that saves headers for you) and know how it operates you can
let your Romanian customers use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top