public BroadcastManager(PresenterModel model, TCPConnectionManager tcpMgr) { IPv6LinkLocalMulticast = IPAddress.Parse("ff02::1"); UseIPv6 = false; //Use IPv6 only if IPv4 is unavailable if ((!Socket.OSSupportsIPv4) && (Socket.OSSupportsIPv6)) { UseIPv6 = true; } this.m_Model = model; this.m_TCPConnectionMgr = tcpMgr; this.m_TCPClassroomMgr = tcpMgr.ClassroomManager; this.m_TCPClientClassrooms = new Hashtable(); this.m_RTPAdvertisedClassrooms = new Hashtable(); m_EventQueue = new ThreadEventQueue(); // this.m_RTPConnectionMgr = rtpMgr; StartListener(); //Subscribe to the instructor advertisements that the BroadcastListener provides m_InstructorAdvertisementCollectionHelper = new InstructorAdvertisementCollectionHelper(this, this.m_Listener); //Subscribe to all the RTP Classrooms to learn when they connect/disconnect. //Notice that we assume there will be no new RTP classrooms created (other than the ones we create in response to advertisements). /*this.m_RtpClassroomConnected = false; * using (Synchronizer.Lock(m_RTPConnectionMgr.Protocol.SyncRoot)) { * foreach (ClassroomModel cm in m_RTPConnectionMgr.Protocol.Classrooms) { * cm.Changed["Connected"].Add(new PropertyEventHandler(OnRtpClassroomConnectedChanged)); * } * }*/ m_IsInstructor = false; using (Synchronizer.Lock(this.m_Model.Participant.SyncRoot)) { //This is the server's identifier which remains constant for the app instance m_SenderID = this.m_Model.Participant.Guid; //Subscribe to the local presenter's role to track when we are instructor this.m_Model.Participant.Changed["Role"].Add(new PropertyEventHandler(OnRoleChanged)); if (this.m_Model.Participant.Role is InstructorModel) { m_IsInstructor = true; } } //Subscribe to the TCP Server to find out when it starts and stops this.m_TCPClassroomMgr.Changed["ServerStarted"].Add(new PropertyEventHandler(ServerStartedChangedHandler)); m_TcpServerStarted = false; using (Synchronizer.Lock(m_TCPClassroomMgr.SyncRoot)) { if (m_TCPClassroomMgr.ServerStarted) { m_TcpServerStarted = true; } } UpdateSenderStatus(); }
//public BroadcastSender(BroadcastMessage message) { public BroadcastSender(IPEndPoint serverEP, PresenterModel model, Guid serverID) { m_ServerEP = serverEP; m_Model = model; m_ServerID = serverID; m_Presentation = null; m_PresentationName = "Untitled Presentation"; m_BufferSyncObject = new object(); //The user can manually disable the broadcast for security/privacy reasons. m_Model.ViewerState.Changed["BroadcastDisabled"].Add(new PropertyEventHandler(OnBroadcastDisabledChanged)); using (Synchronizer.Lock(m_Model.ViewerState.SyncRoot)) { m_BroadcastDisabled = m_Model.ViewerState.BroadcastDisabled; } //Get the initial Participant name. This probably never changes. m_Model.Participant.Changed["HumanName"].Add(new PropertyEventHandler(OnParticipantNameChanged)); using (Synchronizer.Lock(m_Model.Participant.SyncRoot)) { m_ParticipantName = m_Model.Participant.HumanName; } m_Model.ViewerState.Changed["ShowIP"].Add(new PropertyEventHandler(OnShowIPChanged)); using (Synchronizer.Lock(m_Model.ViewerState.SyncRoot)) { this.m_showIP = m_Model.ViewerState.ShowIP; } //Construct an initial broadcast message. UpdateMessage(); //When OnPresentationChange occurs we will update the broadcast message and subscribe the HumanName property of the new //PresentationModel. When the PresentationModel.HumanName changes we will also update the broadcast message. ThreadEventQueue eventQueue = new ThreadEventQueue(); this.m_CurrentPresentationChangedDispatcher = this.m_Model.Workspace.CurrentPresentation.ListenAndInitialize(eventQueue, OnPresentationChanged); m_LocalAddress = GetLocalAddress(); initSocket(); //if init failed.. if (m_Socket == null) { return; } /// Sending to either broadcast address works. Probably we prefer IPAddress.Broadcast /// because this way one broadcast works for multiple interfaces, and it should /// also work on IPv6 networks. IPAddress broadcast = IPAddress.Broadcast; //this is 255.255.255.255 for ipv4. if (BroadcastManager.UseIPv6) { broadcast = BroadcastManager.IPv6LinkLocalMulticast; } m_BroadcastEP = new IPEndPoint(broadcast, BroadcastSender.ListenPort); m_SendThread = new Thread(new ThreadStart(SendThread)); m_SendThread.Start(); }
public BroadcastManager(PresenterModel model, TCPConnectionManager tcpMgr) { IPv6LinkLocalMulticast = IPAddress.Parse("ff02::1"); UseIPv6 = false; //Use IPv6 only if IPv4 is unavailable if ((!Socket.OSSupportsIPv4) && (Socket.OSSupportsIPv6)) { UseIPv6 = true; } this.m_Model = model; this.m_TCPConnectionMgr = tcpMgr; this.m_TCPClassroomMgr = tcpMgr.ClassroomManager; this.m_TCPClientClassrooms = new Hashtable(); this.m_RTPAdvertisedClassrooms = new Hashtable(); m_EventQueue = new ThreadEventQueue(); // this.m_RTPConnectionMgr = rtpMgr; StartListener(); //Subscribe to the instructor advertisements that the BroadcastListener provides m_InstructorAdvertisementCollectionHelper = new InstructorAdvertisementCollectionHelper(this, this.m_Listener); //Subscribe to all the RTP Classrooms to learn when they connect/disconnect. //Notice that we assume there will be no new RTP classrooms created (other than the ones we create in response to advertisements). /*this.m_RtpClassroomConnected = false; using (Synchronizer.Lock(m_RTPConnectionMgr.Protocol.SyncRoot)) { foreach (ClassroomModel cm in m_RTPConnectionMgr.Protocol.Classrooms) { cm.Changed["Connected"].Add(new PropertyEventHandler(OnRtpClassroomConnectedChanged)); } }*/ m_IsInstructor = false; using (Synchronizer.Lock(this.m_Model.Participant.SyncRoot)) { //This is the server's identifier which remains constant for the app instance m_SenderID = this.m_Model.Participant.Guid; //Subscribe to the local presenter's role to track when we are instructor this.m_Model.Participant.Changed["Role"].Add(new PropertyEventHandler(OnRoleChanged)); if (this.m_Model.Participant.Role is InstructorModel) { m_IsInstructor = true; } } //Subscribe to the TCP Server to find out when it starts and stops this.m_TCPClassroomMgr.Changed["ServerStarted"].Add(new PropertyEventHandler(ServerStartedChangedHandler)); m_TcpServerStarted = false; using (Synchronizer.Lock(m_TCPClassroomMgr.SyncRoot)) { if (m_TCPClassroomMgr.ServerStarted) { m_TcpServerStarted = true; } } UpdateSenderStatus(); }
public static int ListenPort = 11303; //TODO: probably shouldn't be hard-coded. //public BroadcastSender(BroadcastMessage message) { public BroadcastSender(IPEndPoint serverEP, PresenterModel model, Guid serverID) { m_ServerEP = serverEP; m_Model = model; m_ServerID = serverID; m_Presentation = null; m_PresentationName = "Untitled Presentation"; m_BufferSyncObject = new object(); //The user can manually disable the broadcast for security/privacy reasons. m_Model.ViewerState.Changed["BroadcastDisabled"].Add(new PropertyEventHandler(OnBroadcastDisabledChanged)); using (Synchronizer.Lock(m_Model.ViewerState.SyncRoot)) { m_BroadcastDisabled = m_Model.ViewerState.BroadcastDisabled; } //Get the initial Participant name. This probably never changes. m_Model.Participant.Changed["HumanName"].Add(new PropertyEventHandler(OnParticipantNameChanged)); using (Synchronizer.Lock(m_Model.Participant.SyncRoot)) { m_ParticipantName = m_Model.Participant.HumanName; } m_Model.ViewerState.Changed["ShowIP"].Add(new PropertyEventHandler(OnShowIPChanged)); using (Synchronizer.Lock(m_Model.ViewerState.SyncRoot)) { this.m_showIP = m_Model.ViewerState.ShowIP; } //Construct an initial broadcast message. UpdateMessage(); //When OnPresentationChange occurs we will update the broadcast message and subscribe the HumanName property of the new //PresentationModel. When the PresentationModel.HumanName changes we will also update the broadcast message. ThreadEventQueue eventQueue = new ThreadEventQueue(); this.m_CurrentPresentationChangedDispatcher = this.m_Model.Workspace.CurrentPresentation.ListenAndInitialize(eventQueue, OnPresentationChanged); m_LocalAddress = GetLocalAddress(); initSocket(); //if init failed.. if (m_Socket == null) { return; } /// Sending to either broadcast address works. Probably we prefer IPAddress.Broadcast /// because this way one broadcast works for multiple interfaces, and it should /// also work on IPv6 networks. IPAddress broadcast = IPAddress.Broadcast; //this is 255.255.255.255 for ipv4. if (BroadcastManager.UseIPv6) { broadcast = BroadcastManager.IPv6LinkLocalMulticast; } m_BroadcastEP = new IPEndPoint(broadcast, BroadcastSender.ListenPort); m_SendThread = new Thread(new ThreadStart(SendThread)); m_SendThread.Start(); }