Exemplo n.º 1
0
 /// <summary>
 /// Finds a match being announced on UDP.
 /// </summary>
 /// <param name="onSessionFound"></param>
 public static void Find(Action <int, IPAddress> onSessionFound)
 {
     if (_announcing)
     {
         StopAnnouncing();
     }
     Network.Network.BroadcastConnect();
     _onSessionFound = onSessionFound;
     _announcment    = new SessionAnnouncment();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Regularly sends a message to all networked SessionAnnouncments.
 /// </summary>
 private void Broadcast()
 {
     _broadcast = true;
     while (_broadcast)
     {
         _announcer = new SessionAnnouncment(_hostID);
         _announcer.Announce();
         // Wait .35 seconds before announcing again.
         Thread.Sleep(BROADCAST_FREQUENCY);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Broadcast that a given hostID has a session available to join.
        /// </summary>
        /// <param name="hostID">ID of the host who's session is available.</param>
        public static void Announce(int hostID)
        {
            // Close existing connections.
            if (Network.Network.Connected)
            {
                Network.Network.Disconnect();
            }
            Network.Network.BroadcastConnect();
            StopAnnouncing();

            // Run an announcment in the background.
            _hostID = hostID;
            var broadcast = new Thread(Broadcast);

            _announcment = new SessionAnnouncment(_hostID);
            broadcast.Start();

            UnityEngine.Debug.Log("Announce");
        }
Exemplo n.º 4
0
 public SessionAnnouncer(ref SessionAnnouncment _announcment)
 {
     _announcer = _announcment;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates an SessionAnnouncment to recieve broadcasted session information.
 /// Sets up the callback for when session is found.
 /// </summary>
 /// <param name="onSessionFound"></param>
 internal void Find(Action <int> onSessionFound)
 {
     _onSessionFound = onSessionFound;
     // Make sure there is an instance of SessionAnnouncment to recieve.
     _announcmentFinder = new SessionAnnouncment();
 }
Exemplo n.º 6
0
 public SessionFinder(ref SessionAnnouncment announcment)
 {
     _announcmentFinder = announcment;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Called when SessionAnnouncment returns with the id
 /// for a hoast advertising a session.
 /// </summary>
 /// <param name="hostID"></param>
 /// <param name="ip"> </param>
 internal static void OnFoundSession(int hostID, IPAddress ip)
 {
     _onSessionFound.Invoke(hostID, ip);
     _announcment = null;
     UnityEngine.Debug.Log("OnFoundSession(" + hostID + "," + ip + ")");
 }