System.Net.Sockets

  • Thread starter Thread starter Charles Law
  • Start date Start date
C

Charles Law

Can anyone let me know what parameter to pass in the following? Any example?

Under System.Net.Sockets

TcpClient.Connect(IPEndPoint)
TcpClient.Connect(IPAddress, Integer)
TcpClient.Connect(String, Integer)

Thanks
Charles Law
 
By said:
But I cannot pass IP Address directly (e.g. 192.168.1.100). How to do it?

The framework unfortunately doesn't like numeric addresses in
TcpClient.Connect(String, Integer). I use IPAddress.Parse to check to
see if the string I've been given is a numeric address, and if so,
connect with Connect(IPAddress, Integer). If it isn't, I just use
Connect(String, Integer)
 
Charles said:
What datatype is IPAddress in TcpClient.Connect(IPAddress, Integer)?

Charles,

you're either new to OO programming or asking strange questions (or it's
just me, never rule that one out ;->)...

It's an object of the class System.Net.IPAddress, which is fully documented
on MSDN.

Cheers,
 
Joerg,

Excuse me for asking stupid question again as I am new to .net programming. :)

Under .Net Framework SDK, the constructor of IPAddress accept long or byte( ) as parameter in order to new an IPAddress Object.

I just wonder if ipaddress (e.g. 192.168.1.100) can be used to new an ipaddress object.

How to change an ipaddress to a long value? (it is not related to .Net)

Thanks
Charles
 
Charles Law said:
Excuse me for asking stupid question again as I am new to .net programming. :)

Under .Net Framework SDK, the constructor of IPAddress accept long or
byte( ) as parameter in order to new an IPAddress Object.

I just wonder if ipaddress (e.g. 192.168.1.100) can be used to new an
ipaddress object.

The easiest way (if you've got it as a String) is to call
IPAddress.Parse.
How to change an ipaddress to a long value? (it is not related to
.Net)

Not sure what you mean by the bit in brackets, but from an IPAddress
you can call GetAddressBytes (but not in the compact framework).

In general, to convert an IP address to a long value, you just take
each byte of the address in turn, which gives you 4 bytes for an IPv4
address and 8 bytes for an IPv6 address. See
IPAddress.NetworkToHostOrder for more details of endianness.
 
Back
Top