public void Start() { lock (mutex) { CheckDisposed(); if (Started) { throw new InvalidOperationException("A browse operation is already running. Cancel it first."); } else if (String.IsNullOrEmpty(service_type)) { throw new ArgumentNullException("ServiceType"); } socket = new SsdpSocket(/*false*/); socket.BeginSendTo(Protocol.CreateDiscoveryRequest(service_type, MX), OnBrowseRequestFinished); // wait for 4 times MX if (AutoStop) { timout_id = client.Dispatcher.Add(TimeSpan.FromSeconds(MX * 3), OnTimeout); } if (!client.Started) { client.Start(false); } } }
public void Stop() { lock (mutex) { CheckDisposed(); if (!started) { return; } WaitHandle[] handles = new WaitHandle[announcers.Count]; int i = 0; foreach (Announcer announcer in announcers.Values) { handles[i++] = announcer.StopAsync(); } request_listener.Stop(); respondSocket.Close(); respondSocket = null; WaitHandle.WaitAll(handles); announceSocket.Close(); announceSocket = null; started = false; } }
public void Start(bool startAnnouncers) { lock (mutex) { CheckDisposed(); if (started) { throw new InvalidOperationException("The Server is already started."); } started = true; request_listener.Start(); announceSocket = new SsdpSocket(); announceSocket.Bind(new IPEndPoint(IPAddress.Any, 0)); respondSocket = new SsdpSocket(false); respondSocket.Bind(new IPEndPoint(IPAddress.Any, Protocol.Port)); if (startAnnouncers) { foreach (Announcer announcer in announcers.Values) { if (!announcer.Started) { announcer.Start(); } } } } }
private void OnBrowseRequestFinished(IAsyncResult asyncResult) { SsdpSocket socket = (SsdpSocket)asyncResult.AsyncState; socket.EndSendTo(asyncResult); AsyncReadResult(socket); }
private void OnByeBye(IAsyncResult asyncResult) { SsdpSocket socket = (SsdpSocket)asyncResult.AsyncState; try { socket.EndSendTo(asyncResult); } catch { } started = false; }
public void Stop() { lock (mutex) { CheckDisposed(); if (timout_id != 0) { client.Dispatcher.Remove(timout_id); timout_id = 0; } if (socket != null) { socket.Close(); socket = null; } } }
private void OnFinished(IAsyncResult asyncResult) { SsdpSocket socket = (SsdpSocket)asyncResult.AsyncState; socket.EndSendTo(asyncResult); }
internal void AsyncReadResult(SsdpSocket socket) { AsyncReadResult(new AsyncReceiveBuffer(socket)); }