Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
javanesevn #1
Member since Apr 2008 · 74 posts · Location: Japan
Group memberships: Members
Show profile · Link to this post
Subject: File-received get error from Vista OS client
Hi all,

I think this is same problem that everyone posted but I still not solve my problem from those information.
And I created  a new thread here and I hope I can get your help.

This snippet code from Connect() function of Jep65Socket.cs
...
            IPAddress ipAddress = null;
            try
            {
                IPAddress[] addresses = Dns.GetHostEntry(Address).AddressList; // raised error when get Vista IP Address follow format fe80::x:x:x:x
                ipAddress = addresses[0];
            }
            catch (SocketException se)
            {
                ipAddress = IPAddress.Parse(Address); //
                Log("Socket error: " + se.Message + " with error code: " + se.ErrorCode);
            }
...

File transfer is ok when sending come from XP to Vista client.
But it got error from Vista OS to XP client because Dns.GetHostEntry() could not resolve IP Address with fe80::x:x:x:x format.


At function:
  HandleStreamHost( ByteStream bs, IQ iq ) {

  ...
           StreamHost[] streamhosts = bs.GetStreamHosts() ;   --> why does streamhosts have both IPv4 and IPv6 format? (Ex: 192.168.10.1 and fe80::x.x.x.x)
          
  ...
  }

At [0] index, it always fe80::x.x.x.x so, that's reason why Dns.GetHostEntry(Address) function forced error.

In different case, if Vista OS have both setting IPv4 and IPv6. What is valid IP addresses in StreamHost[]?

How can I solve this problem for Vista client?

Best regards,
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I have not added IPv6 support to the file transfer example. If you have both a v6 and a v6 address I would suggest to advertise both addresses in the streamhosts. A socket can either listen on Ipv6 or Ipv4, so you have to create 2 listening sockets on the sender client, v6 and v4. The connection client has to parse the ip addresses and create either an v4 or v6 socket.

You can at our code in ClientSocket.cs how to create ipv6 sockets.

Regards,
Alex
Avatar
javanesevn #3
Member since Apr 2008 · 74 posts · Location: Japan
Group memberships: Members
Show profile · Link to this post
Thank you for your suggest, Alex.

I can solved problem on Vista(default setting) with IPv4 and IPv6 enabled. I filtered IPv4 address in process.

string hostname = Dns.GetHostName() ;

IPHostEntry iphe = Dns.GetHostEntry( hostname ) ;

 foreach (IPAddress ip in iphe.AddressList) {
       if ( (ip.AddressFamily == AddressFamily.InterNetwork) && (!IPAddress.IsLoopback(ip)) ) {
            Console.WriteLine("IP address: {0}", ip.ToString());
            bsIq.Query.AddStreamHost(_xmppConnection.MyJID, ip.ToString(), 1000);
       }
 }


But in case IPv6 environment only does not make sense, agsXMPP lib can not create socket IPv6 address.
If Vista client I regarded IPv4 and agsXMPP can not make connection to server.
If Vista with both IPv4 and IPv6 enabled then XP client can not create socket when client received link-local address (fe80:: )

Please correct me if I misunderstand IPv6 environment setting to work with agXMPP library.

Best regards,
Avatar
Alex #4
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
In Jep65Socket.cs

  • you must also listen on v4 and v6 in the function public void Listen(int port) {}
  • parse the Ip address and create the correct socket (v4 or v6) in public override void Connect() {}

Alex
Avatar
javanesevn #5
Member since Apr 2008 · 74 posts · Location: Japan
Group memberships: Members
Show profile · Link to this post
Thank you your reply.

For example, Sender(Vista) and Receiver(XP).

Sender:
   * StreamHost includes IPv6 and IPv4
 
   *
    public void Listen(int port)
        {       
            IPEndPoint lep = new IPEndPoint(IPAddress.Any, port);
            Socket s = new Socket(lep.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                s.Bind(lep);
                s.Listen(0);
                                  
                Console.WriteLine("JEP65: Waiting for a connection...");
                s.BeginAccept(new AsyncCallback(EndAccept), s);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }

Receiver

 public override void Connect()
        {
            base.Connect();
           
            m_ReadBuffer = null;
            m_ReadBuffer = new byte[BUFFERSIZE];

            m_SocksConnected = false;

            IPAddress ipAddress = null;
            try
            {
                //IPHostEntry ipHostInfo = Dns.GetHostByAddress(Address);
                IPHostEntry ipHostInfo = Dns.GetHostEntry(Address);   -->(1)This code raised SocketException((No Such Host is known) when Address field is IPv6 (Ex: fe80::b967:c3ac:e70a:541f%8)
                ipAddress = ipHostInfo.AddressList[0];
            }
            catch (SocketException se)
            {
                ipAddress = IPAddress.Parse(Address);       -->(2) I tried Parse address again  
            }

            IPEndPoint endPoint = new IPEndPoint(ipAddress, Port);

            if (Socket.OSSupportsIPv6 && (endPoint.AddressFamily == AddressFamily.InterNetworkV6))
            {
                _socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); --> (3)threw SocketError.AddressFamilyNotSupported
            }
            else
            {
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            }

            _socket.BeginConnect(endPoint, new AsyncCallback(EndConnect), null);
        }

Above snippet code can not create socket. Does this code match with your suggest?

Best regards,
This post was edited on 2008-10-24, 08:35 by javanesevn.
Avatar
Alex #6
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
On a machine with v4 and v6 enabled you should listen on both v4 and v6. So you need 2 listening sockets.

Alex
Avatar
javanesevn #7
Member since Apr 2008 · 74 posts · Location: Japan
Group memberships: Members
Show profile · Link to this post
Thanks so much, Alex.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS