Ejemplo n.º 1
0
 public ConfigForm()
 {
     InitializeComponent();
     network = new LibUDP();
     listener_exception_delegate = new ListenerExceptionDelegate(ShowExceptionMessage);
     textBox1.Text = "";
 }
Ejemplo n.º 2
0
        public void ListenMessage(int port, ListenerResponseDelegate callback, ListenerExceptionDelegate exception)
        {
            Object[] param = { port, callback, exception };
            //スレッド作成時にデータを渡す
            ParameterizedThreadStart ts = new ParameterizedThreadStart(ListenerStart);

            //スレッド作成
            listener_thread = new Thread(ts);
            listener_thread.Start(param);
            //バックグラウンドスレッドにする
            listener_thread.IsBackground = true;
        }
Ejemplo n.º 3
0
        public JankenForm(ShowConfigFormDelegate show_config, IPAddress address)
        {
            InitializeComponent();
            this.show_config = show_config;
            lbl_result.Text  = "";
            lbl_player1.Text = "";
            lbl_player2.Text = "";
            ResultDelegate result_delegate = new ResultDelegate(JankenResponse);

            this.bt     = new LibJanken(result_delegate);
            this.random = new Random(1000);

            network      = new LibUDP();
            peer_address = address;


            listener_result_delegate    = new ListenerResponseDelegate(ListenerResponse);
            listener_exception_delegate = new ListenerExceptionDelegate(ShowExceptionMessage);
            network.ListenMessage(GAME_PORT, listener_result_delegate, listener_exception_delegate);
        }
Ejemplo n.º 4
0
        private void ListenerStart(Object obj)
        {
            //キャスト
            Object[] param = (Object[])obj;
            //ポートを設定
            int port = (int)param[0];
            ListenerResponseDelegate  callback  = (ListenerResponseDelegate)param[1];
            ListenerExceptionDelegate exception = (ListenerExceptionDelegate)param[2];

            try
            {
                // 通信を監視するエンドポイント
                IPEndPoint remote = new IPEndPoint(IPAddress.Any, port);

                // UdpClientを生成
                listener_client = new UdpClient(port);

                // データ受信を待機(同期処理なので受信完了まで処理が止まる)
                // 受信した際は、 remote にどの IPアドレス から受信したかが上書きされる
                byte[] buffer = listener_client.Receive(ref remote);

                // 受信データを変換
                String response = Encoding.UTF8.GetString(buffer);

                // 受信イベントを実行
                callback(response, remote);
                listener_client.Close();
            }
            catch (ThreadAbortException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                exception(e);
            }
        }