Exemplo n.º 1
0
	//public System.List<string> other_players_uuids;// = new List<string>();
	//private string[] other_players_uuids;// = new string[];
    void Start() {
		other_players_uuids = new ArrayList ();//new List<string>();//string[] {"test"};
		//other_players_uuids.
		//other_players_uuids=new List<String>();
        ws = new WebSocket("ws://www.doodlegrid.com:9000");
		//other_players_uuids.Add ("test");
        ws.OnOpen += OnOpenHandler;
        ws.OnMessage += OnMessageHandler;
        ws.OnClose += OnCloseHandler;

        stateMachine.AddHandler(State.Running, () => {
            new Wait(this, 0.1f, () => {
				//automatically connect
                ws.ConnectAsync();
            });
        });

        stateMachine.AddHandler(State.Connected, () => {
            stateMachine.Transition(State.Ping);
			new Wait(this, 0.05f, () => {
				//automatically connect
				string uniqueID = SystemInfo.deviceUniqueIdentifier;
				ws.SendAsync("[{\"proto\":{\"identity\":\""+uniqueID+"\"}}]", OnIdentComplete);
			});
        });
			

        stateMachine.AddHandler(State.Pong, () => {
        });

        stateMachine.Run();
    }
Exemplo n.º 2
0
    void Start()
    {
        ws = new WebSocket("ws://echo.websocket.org");

        ws.OnOpen    += OnOpenHandler;
        ws.OnMessage += OnMessageHandler;
        ws.OnClose   += OnCloseHandler;

        stateMachine.AddHandler(State.Running, () => {
            new Wait(this, 3, () => {
                ws.ConnectAsync();
            });
        });

        stateMachine.AddHandler(State.Connected, () => {
            stateMachine.Transition(State.Ping);
        });

        stateMachine.AddHandler(State.Ping, () => {
            new Wait(this, 3, () => {
                ws.SendAsync("This WebSockets stuff is a breeze!", OnSendComplete);
            });
        });

        stateMachine.AddHandler(State.Pong, () => {
            new Wait(this, 3, () => {
                ws.CloseAsync();
            });
        });

        stateMachine.Run();
    }
Exemplo n.º 3
0
    void Awake()
    {
        /*
         * 0 - ws://shapelab.kasanzew.de:8080/
         * 1 - ws://ausst04.beuth-hochschule.de:8080/
         * 2 - ws://141.64.52.54:8080/
         */
        ws = new WebSocket(hostadresse[useAdressIndex]);

        ws.OnOpen    += OnOpenHandler;
        ws.OnMessage += OnMessageHandler;
        ws.OnClose   += OnCloseHandler;


        stateMachine.AddHandler(State.Running, () =>
        {
            new Wait(this, 3, () =>
            {
                ws.ConnectAsync();
            });
        });

        stateMachine.AddHandler(State.Recover, () =>
        {
            //Debug.Log("trying to recover connection...");
            new Wait(this, 3, () =>
            {
                ws.ConnectAsync();
            });
        });

        stateMachine.AddHandler(State.LongRecovery, () =>
        {
            new Wait(this, 60, () =>
            {
                stateMachine.Transition(State.Recover);
            });
        });

        stateMachine.AddHandler(State.Terminate, () =>
        {
            new Wait(this, 3, () =>
            {
                ws.CloseAsync();
            });
        });
    }