Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        NetworkTransport.Init();
        servers = new List <PlayerInfo>();

        IPAddress  ip      = IPAddress.Parse("224.5.6.7");
        IPEndPoint localEP = new IPEndPoint(NetworkControl.LocalIPAddress(), multicastPort);

        listener = new UdpClient();
        listener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        listener.Client.Bind(localEP);
        listener.JoinMulticastGroup(ip);
        receive_byte_array = new byte[1024];
        receiveThread      = new Thread(ReceiveData);
        serverList         = new List <PlayerInfo>();
        receiveThread.Start();
    }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        NetworkTransport.Init();
        myIP = NetworkControl.LocalIPAddress().ToString();

        sendingSocket = new UdpClient();
        IPAddress ip = IPAddress.Parse("224.5.6.7");

        sendingSocket.JoinMulticastGroup(ip, 32);
        ipep = new IPEndPoint(ip, multicastPort);

        sendByteArray = Encoding.ASCII.GetBytes(name + "|" +
                                                NetworkControl.LocalIPAddress().ToString());

        ConnectionConfig config = new ConnectionConfig();

        reliableChannelId = config.AddChannel(QosType.ReliableSequenced);
        HostTopology topology = new HostTopology(config, maxConnections);

        hostId = NetworkTransport.AddHost(topology, socketPort);
        Debug.Log("Socket open. Host ID is: " + hostId);

        InvokeRepeating("PingClient", 0, 1);
    }