locked
PeerToPeer API to connect to other IPv6 peer nodes directly RRS feed

  • Question

  • I am trying to use PNRP to send data over the internet using UDP.

    I have seen in MSDN documentation it says
    "
    When attempting to connect to other IPv6 peer nodes directly (without using the Peer Infrastructure), ensure that the socket option IPV6_PROTECTION_LEVEL is set to PROTECTION_LEVEL_UNRESTRICTED.
    "
    How do I set this.


    I am using the following code. But no joy


    UdpClient _udpClient = null;
    int _port = 10666;
    PeerNameRegistration _peerNameRegistration = null;
    IPEndPoint _endPoint = null;

    //Code to start a UDP receiver
    _peerNameRegistration = new PeerNameRegistration();
    _peerNameRegistration.PeerName = new PeerName("Fractal", PeerNameType.Unsecured);
    _peerNameRegistration.Port = _peerToPeerPort;
    _peerNameRegistration.Cloud = Cloud.Global;
    _peerNameRegistration.Comment = "FractalServer: " + DateTime.Now.ToString();
    _peerNameRegistration.UseAutoEndPointSelection = true;
    _if (_peerNameRegistration.IsRegistered() == false)
    {
             _peerNameRegistration.Start();
             System.Diagnostics.Debug.Assert(_peerNameRegistration.IsRegistered() == true);
             string peerHostName = _peerNameRegistration.PeerName.PeerHostName;
             _udpClient = new UdpClient(_port);//, AddressFamily.InterNetwork);
             _endPoint = new IPEndPoint(IPAddress.IPv6Any, 0);
             _udpClient.BeginReceive(UDPReceiver, null);
    }
           
    void UDPReceiver(IAsyncResult result)
    {
        byte[] data = _udpClient.EndReceive(result, ref _endPoint);
        _udpClient.BeginReceive(UDPReceiver, null);
    }

    // Client UDP connect to server code
    PeerNameResolver resolver = new PeerNameResolver();
    PeerName peerName = new PeerName("Fractal", PeerNameType.Unsecured);
    PeerNameRecordCollection peerNameRecordCollection = resolver.Resolve(peerName, Cloud.Global);
    foreach (PeerNameRecord record in peerNameRecordCollection)
    {
         UdpClient udpClient = new UdpClient();
         udpClient.Connect(record.PeerName.PeerHostName, _port);
         byte[] data = System.Text.Encoding.UTF8.GetBytes("Client Send Data To Server");
         int size = udpClient.Send(data, data.Length);
         System.Diagnostics.Debug.Assert(size == data.Length);
         udpClient.Close();
    }

    cheers,
    Dave
    Wednesday, December 9, 2009 12:52 PM

All replies

  • Get the underlying socket from udpclient. Use the setsocketoption to set the value:
    http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.client.aspx
    //set the ipv6 security level
        int   iOptval=PROTECTION_LEVEL_UNRESTRICTED;
        int   iOptLen=sizeof(int);
        int   iErrno;

    SetSockOpt(
                    Socket,
                    IPPROTO_IPV6,                
                    IPV6_PROTECTION_LEVEL,
                    (char*)&iOptval,
                    iOptLen,
                    &iErrno
                    );
    Monday, December 14, 2009 6:39 AM