Hi
I built a .Net library for sending UDP packets to a backend server which works fine in the Unity editor and as a standalone build. When I deploy the game as a web build I get the following error in the Log:
SocketException: Invalid arguments
System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end)
Is there some sort of restrictions on using Sockets in the web player?
Thanks
John T
I’m not sure, but I recall reading that you can’t use plugins in webplayers for security reasons.
I’ve used .NET sockets in the web player without issue, so must be something else causing the issue.
Hmm
This is very strange. Weird how it works in a standalone and not in a web player.I think my problem could be the way in which I try to grab the local IP address:
public Client(string IPAddress, int port)
{
_serverEndPoint = new IPEndPoint(System.Net.IPAddress.Parse(IPAddress), port);
_client.Client.Bind(getAuthEndPoint());
}
private IPEndPoint getAuthEndPoint()
{
string hostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostEntry(hostName);
IPAddress defaultIPAddress = ipEntry.AddressList[0];
return new IPEndPoint(defaultIPAddress, 0);
}
I need to do some debugging… stay tuned…
Thanks
John T
Right, I found the answer to this with a little debugging magic…
When the game runs standalone it picks up the IPv4 address as the first address without issue, but strangely when I run the game in the browser it detects an IPv6 address as the first address.
Now to fix it…
I have to be careful here that I always grab a valid IPv4 address and not stuff like IPv6 and loopback addresses!
John T
Okay
This is my last post on this (unless somebody has a great idea on how to fix this) - otherwise I’m going to add it to the ‘lets do this later’ list…
I have put some logic in the library to check that the detected address is IPv4 and isn’t the loopback address, I just need to be able to bind the UDP client manually from within Unity…
public void Initialise()
{
// if we had trouble automatically binding the auth client...
if(!_sgapClient.Bound)
{
// TODO: Need to get the IP address
string ipToBind = "192.168.0.2"; // temp hack!
_sgapClient.BindClientManually(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ipToBind), 0));
}
}
There we have it… any ideas would be appreciated.
Ta
John T