Hi guys!
First, sorry for my english.
Now, I have a problem with a code which uses sockets. I want connect my script over IPv6 but I receive a SocketException when I run this script in Unity.
The next code works perfect as a Console Application Project in MonoDevelop.
Socket s;
s = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
IPAddress ip = IPAddress.Parse("ff15::2");
s.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, new IPv6MulticastOption(ip));
IPEndPoint ipep = new IPEndPoint(IPAddress.IPv6Any, 26000);
s.Bind(ipep);
while (true) {
byte[] b = new byte[1024];
if (s == null)
Console.WriteLine ("S es null");
else
s.Receive (b);
string str = System.Text.Encoding.ASCII.GetString (b, 0, b.Length);
Console.WriteLine (str.Trim ());
}
}
But the same code (I only changed “Console.WriteLine()” for “Debug.Log()”) doesn’t work as Unity Project. This code break with the exception: “SocketException: An address incompatible with the requested protocol was used.”
Can someone help me?
Thanks!
Santiago.
Is this for web player? I don't think the security sandbox will allow you to create listening sockets there.
– tanoshimiNo, it isn't for web player.
– santiago_sgkWhat does it say on the top of your code, where it says using ....
– SnotE101Sorry, I forgot add the libraries at the top of the code: using UnityEngine; using System.Net; using System.Net.Sockets; using System.Net.NetworkInformation;
– santiago_sgkSame. Did anyone ever get to the bottom of this?
– kew2001