using System.Net;
using System.Net.Sockets;
using UnityEngine.Networking;
var address = IPAddress.Parse("0.0.0.0");
int port;
using (var tempSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) {
tempSocket.Bind(new IPEndPoint(address, port: 0));
port = ((IPEndPoint) tempSocket.LocalEndPoint).Port;
}
var topology = new HostTopology(new ConnectionConfig(), maxDefaultConnections: 100);
var hostId = NetworkTransport.AddHost(topology, port, address.ToString());
Last active
December 4, 2015 16:17
-
-
Save fversnel/7143286f86b671ea019a to your computer and use it in GitHub Desktop.
Get available port for UNET socket
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment