DJ_SG

Hi,

i've one question related to TCPClient. but it's about how to open it.

I've two pieces of VB codes that are used to start a TCP client.

Example A:

Dim ipadd As IPAddress = IPAddress.Parse("192.132.124.100")

Dim port as integer = 6000

_client = New TcpClient

_client.Connect(ipadd, port)

Example B:

Dim ipadd As String = "192.132.124.100"

Dim port as integer = 6000

_client = New TcpClient

_client.Connect(ipadd, port)

I've tried these two examples in normal Windows (XP), they all work well. I mean at least I can establish TCP connections with the server.

However, if i tried them in Windows CE 5.0. Example B sometimes doesn't work. For PocketPC 2003, I have to always use Example A. Can anyone tell me why

thx

DJ




Re: .NET Compact Framework Puzzle: TCPClient.connect

DJ_SG

here is some more information about my puzzle.

I used Example B to develop TCP client application for WinCE 5.0 devices in my project and it wored very well for almost one year. Later we added Pocket PC in our project and it runs MS PocketPC OS, which i guess is another version of WinCE. I found using Example B didn't work in PocketPC: the application could not get connection with remote server. Then i searched MSDN regarding to how to TCPClient and came out with Example A. Luckily it worked for PocketPC.

The weird thing is recently we had a demo of our project prototype to public. For no reason, Example B, which has been working under WinCE 5.0 for more than one year, didn't work anymore. So i tested them using WindowsXP PC and they all work well.

can somebody explain it






Re: .NET Compact Framework Puzzle: TCPClient.connect

DJ_SG

I have checked again the online documentation of TCPClient. It seems to me that I should use

TCPClient.connect(hostname as string, port as integer)

if hostname is the DNS name of the server like www.microsoft.com. If I want to use IP address like "192.168.132.110", I need to convert it to IPAddress by using IPAddress.parse("192.168.132.110"), then use

TCPClient.connect(ipadd as IPAddress, port as integer).

Anyone has any comments






Re: .NET Compact Framework Puzzle: TCPClient.connect

Alan J. McFarlane

Yup, I've seen such things, or at least I /thought/ I did, so I'm glad I'm not the only one. Like you I'm having problems knowing when which of the behaviours occurs. I thought a NETCF program I had used failed if given an IP Address, but it seems now to work... Hmm!

Anyway. The TcpClient documentation, as you note, says, "The DNS name of ...". However, surely it uses the Dns class internally to find the IP Address for the given hostname, and its documentation says:

  • Dns.GetHostAddresses: "The host name or IP address to resolve.", and "...If hostNameOrAddress is an IP address, this address is returned without querying the DNS server."
  • Dns.GetHostEntry: "The host name or IP address to resolve."
  • Dns.Resolve: "A DNS-style host name or IP address."

So, unless TcpClient explicitly checks whether the string is an IP Addresses and blocks then, they will work too.

One guess for why the behaviour might change in different environments is if a DNS lookup is done, sending the IP Address as the 'name'. Then the success of the operation would depend on whether a DNS server is configured, accessible, and what it does if it receives such a query. But I'm not really convinced.

It might be worth asking the question in a NETCF-specific forum, and see if anyone there has noticed this odd behaviour...

Sorry that I couldn't bring more definitive information...






Re: .NET Compact Framework Puzzle: TCPClient.connect

Anthony Wong - MSFT

Yes, TcpClient.Connect(string hostname, int port) uses Dns.GetHostEntry() to retrieve the list of IP addresses even if you pass in an IP address. So if you know the IP address you would like to connect to use, you should use TcpClient.Connect(IPAddress, int).

Cheers,

Anthony Wong [MSFT]





Re: .NET Compact Framework Puzzle: TCPClient.connect

alex2233

have a look at www.dotnetremoting.com , might be helpful