示例#1
0
        private async void connectbutton_ClickAsync(object sender, RoutedEventArgs e)
        {
            mTimer2.Start();
            TextBox TBox = IP;

            Ip = TBox.Text;
            var settings = ApplicationData.Current.LocalSettings;

            settings.Values["IP"]     = Ip;
            serverDisposed.Visibility = Visibility.Collapsed;
            try
            {
                socket = new Windows.Networking.Sockets.StreamSocket();
                Windows.Networking.HostName serverHost = new Windows.Networking.HostName(Ip);
                string serverPort = "1337";
                await socket.ConnectAsync(serverHost, serverPort);

                Stream streamOut = socket.OutputStream.AsStreamForWrite();
                Writer = new StreamWriter(streamOut);
                VerticalPage verticalpage = frame.Content as VerticalPage;
                verticalpage.AppearImg();
                //create timer
                mTimer.Tick    += MTimer_Tick;
                mTimer.Interval = TimeSpan.FromSeconds(5);
                mTimer.Start();

                connectbutton.Visibility = Visibility.Collapsed;
                stackPanel.Visibility    = Visibility.Collapsed;
                serverIP.Visibility      = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
            }
        }
示例#2
0
        private void serverDisposed_Click(object sender, RoutedEventArgs e)
        {
            serverDisposed.Visibility = Visibility.Collapsed;
            connectbutton.Visibility  = Visibility.Visible;
            stackPanel.Visibility     = Visibility.Visible;
            serverIP.Visibility       = Visibility.Visible;

            VerticalPage verticalpage = frame.Content as VerticalPage;

            verticalpage.hideImg();
        }
示例#3
0
        private async void LocalIpAsync()
        {
            try
            {
                var    settings = ApplicationData.Current.LocalSettings;
                object value    = settings.Values["IP"];
                string IPValue  = value.ToString();
                IP.Text = IPValue;
                mTimer2.Start();
                Windows.Networking.HostName serverHost = new Windows.Networking.HostName(IPValue);
                string serverPort = "1337";
                socket = new Windows.Networking.Sockets.StreamSocket();
                await socket.ConnectAsync(serverHost, serverPort);

                Stream streamOut = socket.OutputStream.AsStreamForWrite();
                Writer = new StreamWriter(streamOut);
                //create timer
                mTimer.Tick    += MTimer_Tick;
                mTimer.Interval = TimeSpan.FromSeconds(5);
                mTimer.Start();
                //read data from server
                Stream       streamIn = socket.InputStream.AsStreamForRead();
                StreamReader reader   = new StreamReader(streamIn);
                if (reader != null)
                {
                    connectFalse.Visibility = Visibility.Visible;
                    connectFalse.Content    = reader;
                }
            }
            catch (Exception e)
            {
                connectbutton.Visibility = Visibility.Visible;
                stackPanel.Visibility    = Visibility.Visible;
                serverIP.Visibility      = Visibility.Visible;
                VerticalPage verticalpage = frame.Content as VerticalPage;
                verticalpage.hideImg();
            }
        }