public static SocketSingleton getInstance()
 {
     if (instance == null)
     {
         instance = new SocketSingleton();
     }
     return(instance);
 }
        /// <summary>Handles connecting to the server and starting a game.</summary>
        void onConnecToServer()
        {
            EditText serverText = FindViewById<EditText>(Resource.Id.ServerText);
            EditText userText = FindViewById<EditText>(Resource.Id.UserText);
            EditText oppText = FindViewById<EditText> (Resource.Id.OpponentText);

            serverAddr= serverText.Text;
            uname = userText.Text;

            sockInstance = new SocketSingleton (serverAddr, 8080);
            SocketSingleton.initSingleton ();

            // On "Connect" button click, try to connect to a server.
            progress = ProgressDialog.Show(this, "Loading", "Please Wait...", true);

                if (progress != null)
                    progress.Hide();
                if(!sockInstance.isConnected()){
                    setError("Couldn't connect");
                }else{
                    setError("Connected");
                    Intent intent = new Intent(this,typeof(ChessActivity));
                    ChessActions.socket = sockInstance;
                    ChessActivity.username = userText.Text;
                    ChessActivity.opponent = oppText.Text;
                    ChessActivity.actions = new ChessActions (ChessActivity.username, ChessActivity.opponent);

                    ChessActivity.actions.login ();
                    string read = SocketSingleton.getInstance().getIn().ReadLine();
                    if (read == "TRUE"){
                        if (ChessActivity.actions.joinGame()) {
                            ChessActivity.myTurn = false;
                            ChessActivity.newGame = false;
                            StartActivity(intent);
                        } else {
                            if(ChessActivity.actions.newGame ()) {
                                ChessActivity.myTurn = true;
                                ChessActivity.newGame = true;
                                StartActivity(intent);
                            }
                            else
                                setError("Username already in use for a game.");
                        }
                    } else {
                        setError("Could not use username to login.");
                    }
                }
        }
        public static void initSingleton()
        {
            //	if (instance == null) {
                instance = new SocketSingleton ();
                try{
                        instance.startSocket();
                    outWriter = new StreamWriter(connection.GetStream());
                    outReader = new StreamReader(connection.GetStream());

                //	clientSocket = new Java.Net.Socket(SERVER_IP,SERVER_PORT);
                }catch(System.IO.IOException e){
                    //Print log?
                    System.Console.WriteLine(e.ToString());
                }
            //	}
        }
        public static void initSingleton()
        {
            //	if (instance == null) {
            instance = new SocketSingleton();
            try{
                instance.startSocket();
                outWriter = new StreamWriter(connection.GetStream());
                outReader = new StreamReader(connection.GetStream());


                //	clientSocket = new Java.Net.Socket(SERVER_IP,SERVER_PORT);
            }catch (System.IO.IOException e) {
                //Print log?
                System.Console.WriteLine(e.ToString());
            }
            //	}
        }
 public ChatActions()
 {
     sock = SocketSingleton.getInstance ();
 }
 public ChatActions()
 {
     sock = SocketSingleton.getInstance();
 }
Exemple #7
0
        /// <summary>Handles connecting to the server and starting a game.</summary>
        void onConnecToServer()
        {
            EditText serverText = FindViewById <EditText>(Resource.Id.ServerText);
            EditText userText   = FindViewById <EditText>(Resource.Id.UserText);
            EditText oppText    = FindViewById <EditText> (Resource.Id.OpponentText);

            serverAddr = serverText.Text;
            uname      = userText.Text;

            sockInstance = new SocketSingleton(serverAddr, 8080);
            SocketSingleton.initSingleton();

            // On "Connect" button click, try to connect to a server.
            progress = ProgressDialog.Show(this, "Loading", "Please Wait...", true);

            if (progress != null)
            {
                progress.Hide();
            }
            if (!sockInstance.isConnected())
            {
                setError("Couldn't connect");
            }
            else
            {
                setError("Connected");
                Intent intent = new Intent(this, typeof(ChessActivity));
                ChessActions.socket    = sockInstance;
                ChessActivity.username = userText.Text;
                ChessActivity.opponent = oppText.Text;
                ChessActivity.actions  = new ChessActions(ChessActivity.username, ChessActivity.opponent);

                ChessActivity.actions.login();
                string read = SocketSingleton.getInstance().getIn().ReadLine();
                if (read == "TRUE")
                {
                    if (ChessActivity.actions.joinGame())
                    {
                        ChessActivity.myTurn  = false;
                        ChessActivity.newGame = false;
                        StartActivity(intent);
                    }
                    else
                    {
                        if (ChessActivity.actions.newGame())
                        {
                            ChessActivity.myTurn  = true;
                            ChessActivity.newGame = true;
                            StartActivity(intent);
                        }
                        else
                        {
                            setError("Username already in use for a game.");
                        }
                    }
                }
                else
                {
                    setError("Could not use username to login.");
                }
            }
        }
 public static SocketSingleton getInstance()
 {
     if(instance == null)
         instance = new SocketSingleton();
     return instance;
 }