Exemplo n.º 1
0
        /// <summary>
        /// Opens and returns (with out parameters) a pair of communicating sockets.
        /// </summary>
        private static void OpenSockets(int port, out StringSocketListener server, out StringSocket s1, out SS s2)
        {
            server = new StringSocketListener(port, new UTF8Encoding());
            server.Start();
            SSClient client = new SSClient("localhost", port, new UTF8Encoding());

            s1 = server.AcceptStringSocket();
            s2 = client.Client;
        }
Exemplo n.º 2
0
	public void OnApplicationQuit(){

		try{

			if( this.ssclient != null )
				this.ssclient.Dispose();

		}finally{

			this.ssclient = null;
		}
	}
Exemplo n.º 3
0
	private IEnumerator ProcessMainMenu(){

		this.Blocked = true;

		switch( this.inPut.text.ToUpperInvariant() ){

			case "A":
				var task1 = SSClient.SearchForDevicesType(null);
				yield return new WaitUntil(() => task1.IsCompleted);
				break;

			case "R":
				var task2 = SSClient.SearchForDevicesType("");
				yield return new WaitUntil(() => task2.IsCompleted);
				break;

			case "G":
				var task3 = SSClient.SearchForDevicesType("urn:sbtvd-org:service:GingaCCWebServices:1");
				yield return new WaitUntil(() => task3.IsCompleted);
				break;

			case "I":
				yield return this.ConnectToGinga();

				if( this.ssclient != null ){

					// Change input treatment
					this.menuToProcess = this.ProcessGingaOptions;
					this.ShowGingaOptions();

					this.Blocked = false;
					yield break;
				}

				break;

			case "?":
				break;

			case "X":
				Application.Quit(1);
				break;

			default:
				this.outPut.text += "Unknown command. Press ? for a list of valid commands.\n";
				break;
		}

		this.ShowMenuOptions();
		this.Blocked = false;
	}
Exemplo n.º 4
0
	// Syncronous
	private IEnumerator ConnectToGinga(){

		// Step one: Discover every Ginga devices on the network with SSDP
		var findGingaDevices = SSClient.SearchForDevicesType("urn:sbtvd-org:service:GingaCCWebServices:1");
		yield return new WaitUntil(() => findGingaDevices.IsCompleted);

		// Clean up
		var gingaDevices = findGingaDevices.Result;
		findGingaDevices.Dispose();
		findGingaDevices = null;

		if( gingaDevices.Count == 0 ){

			DebugStream.outPut += "\nNenhum dispositivo Ginga encontrado!\n";
			yield break;
		}

		// Get a chosen discovered Ginga SSDP device
		Rssdp.DiscoveredSsdpDevice chosenGinga = gingaDevices.Values.First();

		// Clean up
		gingaDevices.Clear();
		gingaDevices = null;

		if( !chosenGinga.ResponseHeaders.Contains("LOCATION") ){

			DebugStream.outPut += "\nGinga SSDP response header has no LOCATION key!\n";
			yield break;
		}

		if( chosenGinga.ResponseHeaders.GetValues("LOCATION").Count() == 0 ){

			DebugStream.outPut += "\nGinga SSDP LOCATION response header has no value!\n";
			yield break;
		}

		var gingaHTTPLocation = new Uri(chosenGinga.ResponseHeaders.GetValues("LOCATION").First());

		var finishHandShake = Task.Factory.StartNew(() => {

			try{

				this.ssclient = new SSClient(gingaHTTPLocation,this.OnActionReceived,this.OnApplicationQuit);

				// Debug
				DebugStream.outPut += "Control connection stablished!\n";
				DebugStream.outPut += "Socket.Connected: " + ssclient.Connected.ToString() + "\n";

			}catch( Exception e){

				DebugStream.outPut += "\nSSClient construction failed: " + e.ToString() + "\n";
				Assert.IsNull(this.ssclient);
			}
		});

		yield return new WaitUntil(() => finishHandShake.IsCompleted);
		finishHandShake.Dispose();

		// If connected, it's also listenning
		if( this.ssclient != null )
			this.ssclient.StartListenerCoroutineOn(this);
	}