public void Listen() { Thread listenThread = new Thread(() => { while (true) { Thread.Sleep(10); try { SocketData Dataset = (SocketData)SOCKET.Receive(); //MessageBox.Show(message); ConvertSocketDataReceived(Dataset); Listen(); break; } catch (Exception) { } } }); listenThread.IsBackground = true; listenThread.Start(); }
private void button1_Click(object sender, EventArgs e) { SocketData Test_Data = new SocketData((int)SocketCommand.NOTIFY, new Point(), "ahaha"); SOCKET.Send(Test_Data); }
public void ConvertSocketDataReceived(SocketData Data) { switch (Data.command) { case (int)SocketCommand.FIRST_CONNECT: label_NameGuest.Text = Data.message.ToString(); label_NameMain.Text = form1.MainPlayer.Nickname.ToString(); break; case (int)SocketCommand.SEND_POINT: this.Invoke((MethodInvoker)(() => { coolDownBar.Value = 0; CHESSBOARD.GuestMark(Data.point); })); break; case (int)SocketCommand.NOTIFY: MessageBox.Show(Data.message.ToString()); break; case (int)SocketCommand.NEW_GAME: this.Invoke((MethodInvoker)(() => { //CHESSBOARD.NewGame(); if (MessageBox.Show("Your partner want to make new match, Continue?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { SocketData data = new SocketData((int)SocketCommand.ACCEPT, new Point()); SOCKET.Send(data); CHESSBOARD.NewGame(); } else { SocketData data = new SocketData((int)SocketCommand.IGNORE, new Point()); SOCKET.Send(data); MessageBox.Show("New match request is aborted."); } })); break; case (int)SocketCommand.END_GAME: break; case (int)SocketCommand.QUIT: break; case (int)SocketCommand.ACCEPT: this.Invoke((MethodInvoker)(() => { MessageBox.Show("Your partner accept new match"); CHESSBOARD.NewGame(); })); break; case (int)SocketCommand.IGNORE: this.Invoke((MethodInvoker)(() => { MessageBox.Show("Your partner ignore new match"); })); break; } }