Receive() 개인적인 정적인 메소드

private static Receive ( Socket client ) : void
client Socket
리턴 void
예제 #1
0
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            if (server.isConnected == false)
            {
                string           message = "You are not connected with server.";
                string           caption = "Error";
                MessageBoxButton buttons = MessageBoxButton.OK;
                MessageBoxImage  icon    = MessageBoxImage.Error;
                MessageBox.Show(message, caption, buttons, icon);
            }
            else
            {
                string balance  = "";
                string user     = LoginBox.Text.ToString();
                string password = PasswordBox.Password.ToString();
                String data     = user + ";" + password + "<LOG>";

                server.Send(data);
                sendDone.WaitOne(500);
                server.Receive();
                receiveDone.WaitOne(500);

                string recived = server.receivedData;
                Trace.WriteLine("Response received: " + recived);

                if (recived.IndexOf("<LON>") > -1)
                {
                    string           message = "Check Username/Password.";
                    string           caption = "Error";
                    MessageBoxButton buttons = MessageBoxButton.OK;
                    MessageBoxImage  icon    = MessageBoxImage.Error;
                    MessageBox.Show(message, caption, buttons, icon);
                }
                else if (recived.IndexOf("<LOG>") > -1)
                {
                    int index = recived.IndexOf("<");
                    if (index > 0)
                    {
                        balance = recived.Substring(0, index);
                    }

                    string           message = "Logged in successfully.";
                    string           caption = "Success";
                    MessageBoxButton buttons = MessageBoxButton.OK;
                    MessageBoxImage  icon    = MessageBoxImage.Information;
                    MessageBox.Show(message, caption, buttons, icon);
                    OpenedApp programPage = new OpenedApp(server, user, balance);
                    this.Content = programPage;
                }
            }
        }
        public void ReceiveMessage()
        {
            AsynchronousClient.Receive(AsynchronousClient.sockXML);

            timer.Interval = new TimeSpan(0, 0, 0, 0, 1);
            timer.Tick    += new EventHandler(timer_Tick);
            timer.Start();
        }
예제 #3
0
        /// <summary>
        /// Фиксирует новое входящее подключение.
        /// Подключенный источник сохраняется в карту.
        /// Запсукается ожидание чтения.
        /// </summary>
        private static void AcceptCallback(IAsyncResult ar)
        {
            try
            {
                var server = (AsynchronousServer)ar.AsyncState;
                server._allDone.Set();
                var client = new AsynchronousClient(server._socket.EndAccept(ar));
                ListenerClientMap[server].Add(client);

                client.Receive();
                EventManager.RaiseOnMainThread(EventType.ClientConnected,
                                               client.IsClientSide, client.Socket.LocalEndPoint, client.Socket.RemoteEndPoint);
            }
            catch (Exception e)
            {
                Debug.Log(e);
            }
        }
예제 #4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var serverSocket = AsynchronousSocketListener.GetInstance();

            // サーバーが実行中の場合
            if (serverSocket.IsEnabled)
            {
                // スレッドを停止
                await serverSocket.StopListeningThread();
            }


            // サーバーの起動
            serverSocket.StartListeningThread();

            // 自分のPC名を取得
            string myPC = Environment.MachineName;

            clients.DataReceiveCallback = Non;
            clients.Connect(myPC, 11000);

            clients.Receive();
            clients.Send("CPU<EOF>");


            PN number = new PN()
            {
                playernumber = PlayerNumber
            };

            Application.Current.Properties["Number"] = number;

            play_page         = new Play_page();
            play_page.clients = clients;



            // プレイページへ移動
            this.NavigationService.Navigate(play_page);
        }
예제 #5
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            clients.DataReceiveCallback = DataReceiveCallback;

            await Task.Run(() =>
            {
                do
                {
                    Thread.Sleep(100);
                } while (!Application.Current.Dispatcher.Invoke(() => { return(IsLoaded); }));
            });

            try
            {
                clients.Receive();
                clients.receiveDone.Reset();

                clients.Send("VS<EOF>");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }