Dear Readers,
I am attempting to define an array of IPAddress-es in C#.
I wish to have a array of address so I can try in order to connect to
them in a loop to handle unavailable hosts.
Todate since I do not know how to define an array of IPAddress-es. I
have been defining variable like:
IPAddress ipAddress1 = IPAddress.Parse ( "10.1.1.1" );
IPAddress ipAddress2 = IPAddress.Parse ( "11.1.1.1" );
Then define the end point using the hard coded name.
IPEndPoint remoteServerEnd Point = new IPEndPoint( ipAddress1, port );
How do I declare an array of IPAddress-es so I can loop around them
using an index counter?
I thought I could do IPAddress[] ipAddress = new IPAddress[2];
and then use ipAddress[0] = IPAddress.Parse ( "10.1.1.1" );
This did not work.
What is the correct way to define an array of IPAdresses-es?
Thanks
Stuart 5 11425
Does this create a new IPAddress object? (I've never used this object
before...) IPAddress ipAddress1 = IPAddress.Parse ( "10.1.1.1" );
If so, then I don't see why this would have failed: ipAddress[0] = IPAddress.Parse ( "10.1.1.1" );
Regardless, you can just as easily create an ArrayList.
ArrayList alist = new ArrayList();
alist.Add(IPAdd ress.Parse("10. 2.3.4"));
foreach (IPAddress myIP in alist)
{
// do something with myIP
}
In fact, you could just as easily store an array of IPEndpoint objects in
the ArrayList.
I haven't used any of these objects before, and am not aware of the
sideeffects of using them, or resources that may be allocated. My advice
may be off-base if these are expensive critters.
Good luck,
--- Nick
"Stuart Norris" <st**********@y ahoo.com.au> wrote in message
news:51******** *************** **@posting.goog le.com... Dear Readers,
I am attempting to define an array of IPAddress-es in C#.
I wish to have a array of address so I can try in order to connect to them in a loop to handle unavailable hosts.
Todate since I do not know how to define an array of IPAddress-es. I have been defining variable like:
IPAddress ipAddress1 = IPAddress.Parse ( "10.1.1.1" ); IPAddress ipAddress2 = IPAddress.Parse ( "11.1.1.1" );
Then define the end point using the hard coded name.
IPEndPoint remoteServerEnd Point = new IPEndPoint( ipAddress1, port );
How do I declare an array of IPAddress-es so I can loop around them using an index counter?
I thought I could do IPAddress[] ipAddress = new IPAddress[2];
and then use ipAddress[0] = IPAddress.Parse ( "10.1.1.1" );
This did not work.
What is the correct way to define an array of IPAdresses-es?
Thanks
Stuart
Stuart Norris <st**********@y ahoo.com.au> wrote:
<snip> How do I declare an array of IPAddress-es so I can loop around them using an index counter?
I thought I could do IPAddress[] ipAddress = new IPAddress[2]; and then use ipAddress[0] = IPAddress.Parse ( "10.1.1.1" );
You can.
This did not work.
It should have done. Could you post a short but complete program which
demonstrates the problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
private void button48_Click( object sender, System.EventArg s e)
{
IPAddress[] ips = new IPAddress[5];
string tempIP = "192.168.0. ";
for(int i = 0; i < 5; i++)
{
ips[i] = IPAddress.Parse (tempIP + (i + 1));
}
foreach(IPAddre ss ip in ips)
{
Console.WriteLi ne("IP:"+ip.ToS tring());
}
}
--
William Stacey, MVP
"Stuart Norris" <st**********@y ahoo.com.au> wrote in message
news:51******** *************** **@posting.goog le.com... Dear Readers,
I am attempting to define an array of IPAddress-es in C#.
I wish to have a array of address so I can try in order to connect to them in a loop to handle unavailable hosts.
Todate since I do not know how to define an array of IPAddress-es. I have been defining variable like:
IPAddress ipAddress1 = IPAddress.Parse ( "10.1.1.1" ); IPAddress ipAddress2 = IPAddress.Parse ( "11.1.1.1" );
Then define the end point using the hard coded name.
IPEndPoint remoteServerEnd Point = new IPEndPoint( ipAddress1, port );
How do I declare an array of IPAddress-es so I can loop around them using an index counter?
I thought I could do IPAddress[] ipAddress = new IPAddress[2];
and then use ipAddress[0] = IPAddress.Parse ( "10.1.1.1" );
This did not work.
What is the correct way to define an array of IPAdresses-es?
Thanks
Stuart
For perf it also takes a long...
ips[i] = new IPAddress(byte1 << 24 + byte2 << 16 + byte3 << 8 + byte4);
In a loop, you just increment byte4...
I know, just give me the pleasure of pointing out perf wins. Thats all I get
from this newsgroup ;-) PS, quit storing string IPs in SQL too ;-)
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"William Stacey [MVP]" <st***********@ mvps.org> wrote in message
news:OQ******** ********@TK2MSF TNGP10.phx.gbl. .. private void button48_Click( object sender, System.EventArg s e) { IPAddress[] ips = new IPAddress[5]; string tempIP = "192.168.0. "; for(int i = 0; i < 5; i++) { ips[i] = IPAddress.Parse (tempIP + (i + 1)); } foreach(IPAddre ss ip in ips) { Console.WriteLi ne("IP:"+ip.ToS tring()); } }
-- William Stacey, MVP
"Stuart Norris" <st**********@y ahoo.com.au> wrote in message news:51******** *************** **@posting.goog le.com... Dear Readers,
I am attempting to define an array of IPAddress-es in C#.
I wish to have a array of address so I can try in order to connect to them in a loop to handle unavailable hosts.
Todate since I do not know how to define an array of IPAddress-es. I have been defining variable like:
IPAddress ipAddress1 = IPAddress.Parse ( "10.1.1.1" ); IPAddress ipAddress2 = IPAddress.Parse ( "11.1.1.1" );
Then define the end point using the hard coded name.
IPEndPoint remoteServerEnd Point = new IPEndPoint( ipAddress1, port );
How do I declare an array of IPAddress-es so I can loop around them using an index counter?
I thought I could do IPAddress[] ipAddress = new IPAddress[2];
and then use ipAddress[0] = IPAddress.Parse ( "10.1.1.1" );
This did not work.
What is the correct way to define an array of IPAdresses-es?
Thanks
Stuart
yep. You can also do this if you happen to have the byte[] around:
uint ipnum = BitConverter.To UInt32(ba, 0);
ipAddress = new IPAddress(ipnum );
The IPAddress byte[] constructor does not seem to work or I am using it
wrong.
--
William Stacey, MVP
"Justin Rogers" <Ju****@games4d otnet.com> wrote in message
news:#u******** ******@TK2MSFTN GP09.phx.gbl... For perf it also takes a long...
ips[i] = new IPAddress(byte1 << 24 + byte2 << 16 + byte3 << 8 + byte4);
In a loop, you just increment byte4... I know, just give me the pleasure of pointing out perf wins. Thats all I
get from this newsgroup ;-) PS, quit storing string IPs in SQL too ;-)
-- Justin Rogers DigiTec Web Consultants, LLC. Blog: http://weblogs.asp.net/justin_rogers
"William Stacey [MVP]" <st***********@ mvps.org> wrote in message news:OQ******** ********@TK2MSF TNGP10.phx.gbl. .. private void button48_Click( object sender, System.EventArg s e) { IPAddress[] ips = new IPAddress[5]; string tempIP = "192.168.0. "; for(int i = 0; i < 5; i++) { ips[i] = IPAddress.Parse (tempIP + (i + 1)); } foreach(IPAddre ss ip in ips) { Console.WriteLi ne("IP:"+ip.ToS tring()); } }
-- William Stacey, MVP
"Stuart Norris" <st**********@y ahoo.com.au> wrote in message news:51******** *************** **@posting.goog le.com... Dear Readers,
I am attempting to define an array of IPAddress-es in C#.
I wish to have a array of address so I can try in order to connect to them in a loop to handle unavailable hosts.
Todate since I do not know how to define an array of IPAddress-es. I have been defining variable like:
IPAddress ipAddress1 = IPAddress.Parse ( "10.1.1.1" ); IPAddress ipAddress2 = IPAddress.Parse ( "11.1.1.1" );
Then define the end point using the hard coded name.
IPEndPoint remoteServerEnd Point = new IPEndPoint( ipAddress1, port );
How do I declare an array of IPAddress-es so I can loop around them using an index counter?
I thought I could do IPAddress[] ipAddress = new IPAddress[2];
and then use ipAddress[0] = IPAddress.Parse ( "10.1.1.1" );
This did not work.
What is the correct way to define an array of IPAdresses-es?
Thanks
Stuart
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Riggio |
last post by:
Does anyone know why this property is obsolete? Also, is there an
alternative available?
|
by: ed |
last post by:
What is the difference between IPAddress::Any and IPAddress::Broadcast when
being using by a TCPListener class?
|
by: David Dvali |
last post by:
How can I use System.Net.IPAddress class?
I want assign some IP for example: 85.125.20.60
|
by: Viraptor |
last post by:
Hello
I'm new to c#. I've got arrays in a class:
private DateTime dates;
private IPAddress addrs;
In constructor:
dates = new DateTime; addrs = new IPAddress;
I'm adding some data to it like this:
dates=...; addrs=...; Array.Sort(dates, addrs);
How can I say if there is anything in addrs? Now I'm doing try { }
catch for null references, but there must be a normal way of checking
|
by: helldiversafe-news |
last post by:
Hi all,
I will use a apache soap service with an .net c# client and have a
problem with an complex array:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
| |
by: Ryan Liu |
last post by:
Hi,
Can someone tell me how to calculate an IPaddress's long value?
I have an application which lisiten on a port using UDP protocol. There
could be multiple client sendind UDP data to it and I am only interested
data from one client, I know that client's IP address in form of 127.0.0.1
etc.
I think I need convert that IP into IPaddress then can compare with
|
by: sam.barker0 |
last post by:
Hi,
How can I convert a unsigned char array1 which holds the ipaddress,
into a string
I am using a char array to insert the '.' between the bytes.
I am using a char array because then I can convert it into a string
string address(array);
but when i store it in this way when I store 192 in the char array it
stores "-65"
|
by: sam.barker0 |
last post by:
Hi ,
I am trying to convert from an IPADDRESS string to a
unsigned char array
I tried to use c_str().Its was stupid because I tried to cast it with
<unsigned int.
Is there a way easily do this.
Cheers,
Sam
|
by: David Lazos |
last post by:
Hi All,
I use Contains method of String object to determine if a string variable
has another string, like that.
***************************
ipAddress.Contains("127.0.0")
****************************
supposing that, there is a string array like
|
by: KBJ |
last post by:
Hi,
How can I get IP address of client, which sends request to server via .net
remoting?
Regards,
Kate
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |