PC Review


Reply
Thread Tools Rate Thread

Cannot resolve IP with TcpClient

 
 
Morten Nielsen
Guest
Posts: n/a
 
      14th Mar 2004
I'm trying to connect to server via TcpClient, but gets the following error:
"This is usually a temporary error during hostname resolution and means that
the local server did not receive a response from an authorative server."

The code has been tested in a Windows Application and works fine. I can also
connect to the IP address via Pocket Internet Explorer, so connection should
be fine. I connect via GPRS (which I also have tested to be ok), but it
seems that the error is the same whether or not I have an active internet
connection.

Any idea on what could be wrong?
Code that fails:
-------------------------
TcpClient client;
try
{
client = new TcpClient("129.217.182.51",80); //This one fails
}
catch(System.Exception ex)
{
MessageBox.Show("Error connecting to server:" + ex.Message);
return;
}
-------------------------

I have also tried
IPHostEntry remoteHost = Dns.Resolve("129.217.182.51");
which creates the same error.

Any help or suggestions appreciated

Regards
/Morten Nielsen (email: http://www.iter.dk/contact.aspx )

Implementing GPS in your Pocket PC app?
http://www.iter.dk/software/PocketGpsLib


 
Reply With Quote
 
 
 
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      15th Mar 2004
It looks to me like you are trying to treat the IP address as a host *name*.
DNS isn't going to be able to look that up (it converts names like
"www.microsoft.com" into IP addresses). To use an IP address, you really
want to create the TcpClient instance with the default constructor and then
tell it to connect.

client = new TcpClient();
client.Connect( IPAddress.Parse( yourstring ), portnumber );

Paul T.

"Morten Nielsen" <(E-Mail Removed)> wrote in message
news:c323gm$30ng$(E-Mail Removed)...
> I'm trying to connect to server via TcpClient, but gets the following

error:
> "This is usually a temporary error during hostname resolution and means

that
> the local server did not receive a response from an authorative server."
>
> The code has been tested in a Windows Application and works fine. I can

also
> connect to the IP address via Pocket Internet Explorer, so connection

should
> be fine. I connect via GPRS (which I also have tested to be ok), but it
> seems that the error is the same whether or not I have an active internet
> connection.
>
> Any idea on what could be wrong?
> Code that fails:
> -------------------------
> TcpClient client;
> try
> {
> client = new TcpClient("129.217.182.51",80); //This one fails
> }
> catch(System.Exception ex)
> {
> MessageBox.Show("Error connecting to server:" + ex.Message);
> return;
> }
> -------------------------
>
> I have also tried
> IPHostEntry remoteHost = Dns.Resolve("129.217.182.51");
> which creates the same error.
>
> Any help or suggestions appreciated
>
> Regards
> /Morten Nielsen (email: http://www.iter.dk/contact.aspx )
>
> Implementing GPS in your Pocket PC app?
> http://www.iter.dk/software/PocketGpsLib
>
>



 
Reply With Quote
 
Morten Nielsen
Guest
Posts: n/a
 
      15th Mar 2004
> It looks to me like you are trying to treat the IP address as a host
*name*.
> DNS isn't going to be able to look that up (it converts names like
> "www.microsoft.com" into IP addresses). To use an IP address, you really
> want to create the TcpClient instance with the default constructor and

then
> tell it to connect.
>
> client = new TcpClient();
> client.Connect( IPAddress.Parse( yourstring ), portnumber );


Thanks a lot. That 'kinda' helped. Now I'm getting a completely new and way
more strange error:
A managed SocketException occured at Application::Run+0xf
An unknown, invalid, or unsupported option or level was specified in a
getsockopt or setsockopt call.

Is far as I can understand from this page:


 
Reply With Quote
 
Morten Nielsen
Guest
Posts: n/a
 
      15th Mar 2004
> It looks to me like you are trying to treat the IP address as a host
*name*.
> DNS isn't going to be able to look that up (it converts names like
> "www.microsoft.com" into IP addresses). To use an IP address, you really
> want to create the TcpClient instance with the default constructor and

then
> tell it to connect.
>
> client = new TcpClient();
> client.Connect( IPAddress.Parse( yourstring ), portnumber );


Thanks a lot. That 'kinda' helped. Now I'm getting a completely new and way
more strange error (when running client.Connect(...)) :
"A managed SocketException occured at Application::Run+0xf
An unknown, invalid, or unsupported option or level was specified in a
getsockopt or setsockopt call."

Is far as I can understand from this page:
http://www.dotnet247.com/247referenc...43/216044.aspx
there's something about .NET CF isn't supporting option and level (whatever
that means). The answer doesn't make much sense to me either. Can anyone
give me a pointer on what I can do -especially since I'm only using sockets
indirectly (that is TcpClient).

/Morten


 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      15th Mar 2004
Post the code for the routine that errors out. I've done this a bunch and
it never fails. Also, tell us where the debugger drops you when that
exception is fired.

By the way, if the server isn't listening for you on that port, you *will*
get an exception...

Paul T.

"Morten Nielsen" <(E-Mail Removed)> wrote in message
news:c35d0g$hfl$(E-Mail Removed)...
> > It looks to me like you are trying to treat the IP address as a host

> *name*.
> > DNS isn't going to be able to look that up (it converts names like
> > "www.microsoft.com" into IP addresses). To use an IP address, you

really
> > want to create the TcpClient instance with the default constructor and

> then
> > tell it to connect.
> >
> > client = new TcpClient();
> > client.Connect( IPAddress.Parse( yourstring ), portnumber );

>
> Thanks a lot. That 'kinda' helped. Now I'm getting a completely new and

way
> more strange error:
> A managed SocketException occured at Application::Run+0xf
> An unknown, invalid, or unsupported option or level was specified in a
> getsockopt or setsockopt call.
>
> Is far as I can understand from this page:
>
>



 
Reply With Quote
 
Morten Nielsen
Guest
Posts: n/a
 
      16th Mar 2004
The code:
---------------------------------------
private void StartNTRIP2()
{
IPAddress BroadCasterIP = IPAddress.Parse("129.217.182.51");
int BroadCasterPort = 80;
TcpClient client;
client = new TcpClient();
try
{
client.Connect(BroadCasterIP,BroadCasterPort); // <== This one fails
}
catch(System.Exception ex)
{
MessageBox.Show("Error connecting to server:" + ex.Message);
return;
}
}
---------------------------------------

I have completely rewritten the code to use a socket instead. Even though
TcpClient actually is a socket connection, it works much better with a
socket instead (even through ActiveSync where I can't even get Pocket
Internet Explorer to work!!!). I liked the TcpClient approach better though.
It was much simpler an cleaner code.

But this doesn't change the fact that I just finished my prototype of
something REALLY cool. I'm gonna be rich !!! :-)

Regards
/Morten Nielsen


 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      16th Mar 2004
Well, I don't see anything wrong there. It's possible that some option that
the TcpClient sets by default doesn't exist on an ActiveSync connection, if
that's what you're using. That code works fine for me with network
connectivity...

Paul T.

"Morten Nielsen" <(E-Mail Removed)> wrote in message
news:c35j7e$ik9$(E-Mail Removed)...
> The code:
> ---------------------------------------
> private void StartNTRIP2()
> {
> IPAddress BroadCasterIP = IPAddress.Parse("129.217.182.51");
> int BroadCasterPort = 80;
> TcpClient client;
> client = new TcpClient();
> try
> {
> client.Connect(BroadCasterIP,BroadCasterPort); // <== This one

fails
> }
> catch(System.Exception ex)
> {
> MessageBox.Show("Error connecting to server:" + ex.Message);
> return;
> }
> }
> ---------------------------------------
>
> I have completely rewritten the code to use a socket instead. Even though
> TcpClient actually is a socket connection, it works much better with a
> socket instead (even through ActiveSync where I can't even get Pocket
> Internet Explorer to work!!!). I liked the TcpClient approach better

though.
> It was much simpler an cleaner code.
>
> But this doesn't change the fact that I just finished my prototype of
> something REALLY cool. I'm gonna be rich !!! :-)
>
> Regards
> /Morten Nielsen
>
>



 
Reply With Quote
 
Morten Nielsen
Guest
Posts: n/a
 
      17th Mar 2004
> Well, I don't see anything wrong there. It's possible that some option
that
> the TcpClient sets by default doesn't exist on an ActiveSync connection,

if
> that's what you're using. That code works fine for me with network
> connectivity...


As I said in the beginning, I use GPRS (modem) connection.

/Morten


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User SID's won't resolve, group SID's seem to resolve Rich Microsoft Windows 2000 Security 0 6th Jan 2009 08:50 PM
TcpClient EdisonCPP Microsoft Dot NET Framework 5 7th Jun 2007 03:54 PM
TcpClient Adam Goetz Microsoft Dot NET Compact Framework 1 2nd Sep 2004 04:29 PM
Cannot resolve text-URLs, but can resolve IP adrs Kevin F Microsoft Windows 2000 DNS 1 24th Jun 2004 03:37 AM
TcpClient Jeremy Summers Microsoft ASP .NET 0 21st Oct 2003 12:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:30 AM.