Beispiel #1
0
 /// <summary>向同一桌的两个客户端发送信息</summary>
 /// <param name="gameTable">指定游戏桌</param>
 /// <param name="str">信息</param>
 public void SendToBoth(GameTable gameTable, string str)
 {
     for (int i = 0; i < 2; i++)
     {
         if (gameTable.gamePlayer[i].someone == true)
         {
             AsyncSendToOne(gameTable.gamePlayer[i].user, str);
         }
     }
 }
Beispiel #2
0
 /// <summary>【开始服务】按钮的Click事件</summary>
 private void buttonStart_Click(object sender, EventArgs e)
 {
     if (int.TryParse(textBoxMaxTables.Text, out maxTables) == false
         || int.TryParse(textBoxMaxUsers.Text, out maxUsers) == false)
     {
         MessageBox.Show("请输入在规定范围内的正整数");
         return;
     }
     if (maxUsers < 1 || maxUsers > 300)
     {
         MessageBox.Show("允许进入的人数只能在1-300之间");
         return;
     }
     if (maxTables < 1 || maxTables > 100)
     {
         MessageBox.Show("允许的桌数只能在1-100之间");
         return;
     }
     textBoxMaxUsers.Enabled = false;
     textBoxMaxTables.Enabled = false;
     //初始化数组
     gameTable = new GameTable[maxTables];
     for (int i = 0; i < maxTables; i++)
     {
         gameTable[i] = new GameTable(listBox1);
     }
        // myListener = new TcpListener(localAddress, port);
     myListener = new TcpListener(IPAddress.Any, port);
     myListener.Start();
     service.AddItem(string.Format("开始在{0}:{1}监听客户连接", localAddress, port));
     //创建一个线程监听客户端连接请求
     ThreadStart ts = new ThreadStart(ListenClientConnect);
     Thread myThread = new Thread(ts);
     myThread.Start();
     buttonStart.Enabled = false;
     buttonStop.Enabled = true;
 }