Beispiel #1
0
 void GetChatForm(Control ctrl, string formName)
 {
     if (ctrl.InvokeRequired)
     {
         ctrl.Invoke(_formGetter, ctrl, formName);
     }
     else
     {
         foreach (Form frm in Application.OpenForms)
         {
             if (frm.Name == formName)
             {
                 frm.Activate();
                 return;
             }
         }
         ClientForm2 dlgchat = new ClientForm2(this);
         dlgchat.Show();
         if (formMadeByRcv == true)
         {
             AnySound.spMsgRcv.Play();
         }
         dlgchat.txtTTS.Focus();
     }
 }
Beispiel #2
0
        void DataReceived(IAsyncResult ar)
        {
            // BeginReceive에서 추가적으로 넘어온 데이터를 AsyncObject 형식으로 변환한다.
            AsyncObject obj = (AsyncObject)ar.AsyncState;

            // 데이터 수신을 끝낸다.
            int received = obj.WorkingSocket.EndReceive(ar);

            // 받은 데이터가 없으면(연결끊어짐) 끝낸다.
            if (received <= 0)
            {
                obj.WorkingSocket.Close();
                return;
            }


            formMadeByRcv = true;
            GetChatForm(this, "ClientForm2");


            string text = Encoding.UTF8.GetString(obj.Buffer);

            Control     ctrl = Control.FromHandle(this.formHandle);
            ClientForm2 clf2 = (ClientForm2)ctrl;

            clf2.AppendText(string.Format("관리자: {0}", text));


            obj.ClearBuffer();

            // 수신 대기
            obj.WorkingSocket.BeginReceive(obj.Buffer, 0, 4096, 0, DataReceived, obj);
        }