Net.IPAddress.New and Byte[] - SOLVED

Using (or providing) Microsoft.NET Classes
Post Reply
Tomas Gustafsson
Posts: 101
Joined: Mon Sep 19, 2011 6:43 pm

Net.IPAddress.New and Byte[] - SOLVED

Post by Tomas Gustafsson »

Begging for help. I'm quite desperate with this.

Method: UdpClient.SendAsync Method (Byte[], Int32, IPEndPoint)

The call above willingly takes the Byte[] part by using 83 ⎕DR [text data to send], so to that part it's seems ok.

The problem is System.Net.IPEndPoint:
http://msdn.microsoft.com/en-us/library/system.net.ipendpoint.aspx

Code: Select all

public IPEndPoint(
   IPAddress address,
   int port
)

IPEndPoint.New requires an IP address and a port. It works if the IP address is IP4, then i can pass the 4 integers to the IPAddress constructor, and it goes right.

BUT: I must pass IPv6 addresses, that i manage as text vectors. An IPv6 address is eg. 'fe80::f9cc:d1aa:520a:4f1%11'.

I've tried everything that comes to my mind. But i'm simply unable to construct an IPAddress, because it requires Byte[].

http://msdn.microsoft.com/en-us/library/s128tyf6.aspx

Code: Select all

public IPAddress(
   byte[] address
)

I'd like to say eg.:

IPAddress.New ⊂'fe80::f9cc:d1aa:520a:4f1%11'

No go, as all related options, since they all use Byte[].

How do i create the IPAddress object? This simple, annoying problem invalidates everyting. I saw there was some Byte[] discussion in the forum, but no good solution. I cannot loop through the address character by character; even if i can create a System.Array.CreateInstance(Byte), i wouldn't like to populate it by looping - too little time for that! There must be a better solution!?!?

(APl 13.2, framework 4.5)
Tomas Gustafsson
Posts: 101
Joined: Mon Sep 19, 2011 6:43 pm

Re: Net.IPAddress.New and Byte[] - SOLVED

Post by Tomas Gustafsson »

And the solution:

IPAddress has a Parse method, that allows one to pass on a text style IPv6 address.

Code: Select all

ip←Net.IPAddress.IPv6Any.Parse ⊂'fe80::1c73:3e99:60d9:9b14%14'
ep←IPEndPoint.New ip 7777
{}mySocket.SendAsync (83 ⎕DR textdata) (''⍴⍴textdata) ep

The Byte[] problem remains in various other methods related to handling IP addresses.
Post Reply