Esempio n. 1
0
 /// <summary>
 /// Public method to instantiate ServerMessageReceiver singleton.
 /// </summary>
 /// <returns></returns>
 public static MessageReceiver GetInstance()
 {
     return _instance ?? (_instance = new MessageReceiver());
 }
Esempio n. 2
0
        public async void Connect()
        {
            var mainPageViewModel = MainPageViewModel.GetInstance();

            if (mainPageViewModel.ConnectionStatus)
            {
                return;
            }

            var localPort = "4032";
            var localHostName = new HostName("192.168.1.2");

            // Currently doesn't work.
            var OzwegoProduction = new HostName("138.91.91.144");
            var OzwegoPort = "4032";

            var OzwegoStaging = new HostName("138.91.89.40");
            var OzwegoStagingPort = "4032";

            TcpSocket = new StreamSocket();

            try
            {
                //await TcpSocket.ConnectAsync(localHostName, localPort);
                await TcpSocket.ConnectAsync(OzwegoStaging, OzwegoStagingPort);

                mainPageViewModel.ConnectionStatus = true;

                messageReceiver = MessageReceiver.GetInstance();
                messageSender = MessageSender.GetInstance();

                await messageSender.SendMessage(PacketType.c_LogIn, Settings.userInstance);


                //
                // Now wait for incoming messages from the server.
                //

                await messageReceiver.WaitForData();
            }
            catch (Exception e)
            {
                //ToDo: Re-enable the code below.
//#if DEBUG
//                // Throw an exception if it's not due to the server not running.
//                if (e.HResult != -2147014835)
//                {
//                    throw;
//                }
//#endif
//                //
//                // If this is an unknown status, it means that the error is fatal and retry will
//                // likely fail.
//                //

//                if (SocketError.GetStatus(e.HResult) == SocketErrorStatus.Unknown)
//                {
//                    throw;
//                }

                // ToDo: Retry the connection here.

                //ToDo: This call throws a taskCanceled exception if you jam the button...
                Disconnect();
            }
        }