Ejemplo n.º 1
0
        //데이터 송신
        private void SendData(Command cmd, IPEndPoint receiverIp)
        {
            byte[] byteBuf;
            Data sendData;
            Command returnCmd = cmd;

            sendData = new Data();
            sendData.Cmd = cmd;
            byteBuf = new byte[4];
            byteBuf = sendData.ToByte();
            try
            {
                udpData.BeginSend(byteBuf, byteBuf.Length, receiverIp, new AsyncCallback(SendDataCallback), returnCmd);
            }
            catch (Exception e) { }
        }
Ejemplo n.º 2
0
 private void ReceiveDataCallback(IAsyncResult ar)
 {
     tempIP = new IPEndPoint(IPAddress.Any, 0);
     try
     {
         Data receiveData = new Data(udpData.EndReceive(ar, ref tempIP));
         //데이터 cmd에 따른 분기
         switch (receiveData.Cmd)
         {
             case Command.Invite:
                 {
                     string temp = lbl_status.Text;
                     ShowStatus("연결 요청 수신");
                     if (MessageBox.Show("통신 요청을 수락하시겠습니까?",
                         "통신 요청 알림",
                         MessageBoxButtons.YesNo,
                         MessageBoxIcon.None) == DialogResult.Yes)
                     {
                         SendData(Command.OK, tempIP);
                         InitUdpVoice();
                         InitCall();
                     }
                     else
                     {
                         ShowStatus(temp);
                         SendData(Command.NO, tempIP);
                     }
                     break;
                 }
             case Command.OK:
                 {
                     MessageBox.Show("통신 요청이 수락되었습니다.", "통신 연결 알림", MessageBoxButtons.OK);
                     InitCall();
                     break;
                 }
             case Command.NO:
                 {
                     udpVoice.Close();
                     break;
                 }
             case Command.SpeakingOn:
                 {
                     SetBtn(2);
                     break;
                 }
             case Command.SpeakingOff:
                 {
                     SetBtn(3);
                     break;
                 }
             case Command.Close:
                 {
                     Stop();
                     MessageBox.Show("상대방이 연결을 차단하였습니다.", "통신 차단 알림", MessageBoxButtons.OK);
                     break;
                 }
             default:
                 {
                     break;
                 }
         }
         OnReceiveData();
     }
     catch (Exception e) { }
 }