void OnSendData(object sender, EventArgs e)
        {
            // 서버가 대기중인지 확인한다.
            if (!mainSock.IsBound)
            {
                MsgBoxHelper.Warn("서버가 실행되고 있지 않습니다!");
                return;
            }

            // 보낼 텍스트
            tts = txtTTS.Text.Trim();


            if (string.IsNullOrEmpty(tts))
            {
                MsgBoxHelper.Warn("텍스트가 입력되지 않았습니다!");
                txtTTS.Focus();
                return;
            }

            // ID 와 메세지를 담도록 만든다.

            /*
             * // 문자열을 utf8 형식의 바이트로 변환한다.
             * byte[] bDts = Encoding.UTF8.GetBytes(nameID + ':' + tts);
             *
             * // 서버에 전송한다.
             * mainSock.Send(bDts);
             *
             * // 전송 완료 후 텍스트박스에 추가하고, 원래의 내용은 지운다.
             * AppendText(txtHistory, string.Format("[보냄]{0}: {1}", nameID, tts));
             * txtTTS.Clear();
             *
             */

            dot_x = p.X.ToString(); //x좌표를 int형에서 string 값으로 서버에게 보냄
            dot_y = p.Y.ToString(); //y좌표를 int형에서 string 값으로 서버에게 보냄

            // 문자열을 utf8 형식의 바이트로 변환한다.
            byte[] x = Encoding.UTF8.GetBytes(nameID + ':' + tts + ':' + dot_x + ':' + dot_y);

            // 서버에 전송한다.
            mainSock.Send(x);

            // 전송 완료 후 텍스트박스에 추가하고, 원래의 내용은 지운다.
            AppendText(txtHistory, string.Format("[보냄]{0}: {1}, x좌표{2}, y좌표{3}", nameID, tts, dot_x, dot_y));
            Console.WriteLine(dot_x);
            Console.WriteLine(dot_y);

            txtTTS.Clear();
        }
        private void PictureBox1_Click(object sender, EventArgs e)
        {
            if (!mainSock.IsBound)
            {
                MsgBoxHelper.Warn("서버가 실행되고 있지 않습니다!");
                return;
            }

            dot_x = p.X.ToString();
            dot_y = p.Y.ToString();
            byte[] x = Encoding.UTF8.GetBytes(nameID + ':' + tts + ':' + dot_x + ':' + dot_y + ':');
            mainSock.Send(x);
            AppendText(txtHistory, string.Format("[보냄]: {0}, x좌표{1}, y좌표{2}", tts, dot_x, dot_y));
        }
Example #3
0
 // 그림 맞추기방 버튼
 private void OpenPaintGame(object sender, EventArgs e)
 {
     if (ClientList.CheckedItems.Count == 0)
     {
         MsgBoxHelper.Error("사용자를 선택해주세요.");
         return;
     }
     for (int i = ClientList.CheckedItems.Count - 1; i >= 0; i--)
     {
         if (Nick_label.Text.Equals(ClientList.CheckedItems[i].ToString()))
         {
             MsgBoxHelper.Error("본인을 제외한 사용자를 선택해주세요.");
             return;
         }
     }
     pg = new Paint_Game(this, Nick_label.Text);
     pg.Show();
 }
Example #4
0
        void OnSendData(object sender, EventArgs e)
        {
            // 서버가 대기중인지 확인한다.
            if (!mainSock.IsBound)
            {
                MsgBoxHelper.Warn("서버가 실행되고 있지 않습니다!");
                return;
            }

            // 보낼 텍스트
            string tts = txtTTS.Text.Trim();

            if (string.IsNullOrEmpty(tts))
            {
                MsgBoxHelper.Warn("텍스트가 입력되지 않았습니다!");
                txtTTS.Focus();
                return;
            }

            // string[] tokens = tts.Split(':');
            byte[] bDts = new byte[4096];
            //AppendText(txtHistory, tokens.Length.ToString());
            AppendText(txtHistory, tts);

            if (comboBox1.SelectedItem.Equals("BR"))
            {
                bDts = Encoding.UTF8.GetBytes("BR:" + nameID + ':' + tts + ':');
                AppendText(txtHistory, string.Format("[전체전송]{0}", tts));
            }
            else
            {
                // 문자열을 utf8 형식의 바이트로 변환한다.
                bDts = Encoding.UTF8.GetBytes("TO:" + nameID + ':' + comboBox1.SelectedItem + ':' + tts + ':');
                AppendText(txtHistory, string.Format("[{0}에게 보냄]:{1}", comboBox1.SelectedItem, tts));
            }


            // 서버에 전송한다.
            mainSock.Send(bDts);

            // 전송 완료 후 텍스트박스에 추가하고, 원래의 내용은 지운다.
            //AppendText(txtHistory, string.Format("[보냄]{0}:{1}", nameID, tts));
            txtTTS.Clear();
        }
Example #5
0
        void OnSendData(object sender, EventArgs e)
        {
            // 서버가 대기중인지 확인한다.
            if (!mainSock.IsBound)
            {
                MsgBoxHelper.Warn("서버가 실행되고 있지 않습니다!");
                return;
            }

            // 보낼 텍스트
            string tts = txtTTS.Text.Trim();

            if (string.IsNullOrEmpty(tts))
            {
                MsgBoxHelper.Warn("텍스트가 입력되지 않았습니다!");
                txtTTS.Focus();
                return;
            }

            // ID 와 메세지를 담도록 만든다.

            // 문자열을 utf8 형식의 바이트로 변환한다.
            //byte[] bDts = Encoding.UTF8.GetBytes(nameID + ':' + tts);
            string[] tokens = tts.Split(':');
            byte[]   bDts   = new byte[4096];
            if (tokens[0].Equals("BR"))
            {
                bDts = Encoding.UTF8.GetBytes
                           ("BR:" + nameID + ':' + tokens[1] + ':');
            }
            else
            {
                bDts = Encoding.UTF8.GetBytes
                           ("TO:" + nameID + ':' + tokens[0] + ':' + tokens[1] + ':');
            }

            // 서버에 전송한다.
            mainSock.Send(bDts);

            // 전송 완료 후 텍스트박스에 추가하고, 원래의 내용은 지운다.
            AppendText(txtHistory, string.Format("[보냄]{0}: {1}", nameID, tts));
            txtTTS.Clear();
        }
Example #6
0
        void OnSendData(object sender, EventArgs e)
        {
            // 서버가 대기중인지 확인한다.
            if (!mainSock.IsBound)
            {
                MsgBoxHelper.Warn("서버가 실행되고 있지 않습니다!");
                return;
            }

            // 보낼 텍스트
            string tts = txtTTS.Text.Trim();

            if (string.IsNullOrEmpty(tts))
            {
                MsgBoxHelper.Warn("텍스트가 입력되지 않았습니다!");
                txtTTS.Focus();
                return;
            }

            // ID 와 메세지를 담도록 만든다.

            // 문자열을 utf8 형식의 바이트로 변환한다.
            DataForm dataForm = new DataForm();

            dataForm.id   = nameID;
            dataForm.text = tts;
            dataForm.req  = "msg";
            string request = JsonConvert.SerializeObject(dataForm);

            byte[] bDts = Encoding.UTF8.GetBytes(request);
            // Encoding.UTF8.GetBytes(nameID + '`' + tts);


            // 서버에 전송한다.
            mainSock.Send(bDts);

            // 전송 완료 후 텍스트박스에 추가하고, 원래의 내용은 지운다.
            AppendText(txtHistory, string.Format("[나]{0} : {1}", dataForm.id, dataForm.text));
            txtTTS.Clear();
        }
Example #7
0
 // 중복 체크
 private void Overlap_Check(object sender, EventArgs e)
 {
     if (!ServerConnected)
     {
         int port = 15000;
         try
         {
             mainSock.Connect(txtServerIP.Text, port);
             ServerConnected = true;
             AsyncObject obj = new AsyncObject(50000);
             obj.WorkingSocket = mainSock;
             mainSock.BeginReceive(obj.Buffer, 0, obj.BufferSize, 0, DataReceived, obj);
         }
         catch (Exception ex)
         {
             MsgBoxHelper.Error("연결에 실패했습니다!\n오류 내용: {0}", MessageBoxButtons.OK, ex.Message);
             return;
         }
     }
     byte[] bDts = Encoding.UTF8.GetBytes("7" + '\x01' + mainSock.LocalEndPoint.ToString() + '\x01' + txtNick.Text + '\x01');
     mainSock.Send(bDts);
 }
Example #8
0
        private void OnConnectToServer(object sender, EventArgs e)
        {
            if (mainSock.Connected)
            {
                MsgBoxHelper.Error("이미 연결되어 있습니다!");
                return;
            }

            int port = 15000;           //고정

            nameID = txtID.Text.Trim(); //ID
            if (string.IsNullOrEmpty(nameID))
            {
                MsgBoxHelper.Warn("ID가 입력되지 않았습니다!");
                txtID.Focus();
                return;
            }

            // 서버에 연결
            try
            {
                mainSock.Connect(txtAddress.Text, port);
            }
            catch (Exception ex)
            {
                MsgBoxHelper.Error("연결에 실패했습니다!\n오류 내용: {0}", MessageBoxButtons.OK, ex.Message);
                return;
            }

            // 서버로 ID 전송
            SendID();

            // 연결 완료, 서버에서 데이터가 올 수 있으므로 수신 대기한다.
            AsyncObject obj = new AsyncObject(4096);

            obj.WorkingSocket = mainSock;
            mainSock.BeginReceive(obj.Buffer, 0, obj.BufferSize, 0, DataReceived, obj);
        }
Example #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (Form frmm in Application.OpenForms)
            {
                if (frmm.Name == "Client")
                {
                    frmm.Activate();
                    MessageBox.Show("이미 실행중입니다.", "경고", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            if (mainSock.Connected)
            {
                MsgBoxHelper.Error("이미 연결되어 있습니다!");
                return;
            }

            //닉네임칸이 빈칸이라면 메시지 박스
            string name = txtNick.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                MsgBoxHelper.Warn("닉네임을 입력해 주세요");
                txtNick.Focus();
                return;
            }

            //클라에게 닉네임을 넘겨준다
            //Client.nick = txtNick.Text;
            //클라에게 ip주소를 넘겨준다
            //Client.s_ip = txtAddress.Text;

            Client frm = new Client();

            frm.Show();
        }
Example #10
0
        void OnConnectToServer(object sender, EventArgs e)
        {
            // 연결 버튼

            if (btnConnect.Text.Equals("연결끊기"))
            {
                // 문자열을 utf8 형식의 바이트로 변환한다.
                DataForm dataForm = new DataForm();
                dataForm.id   = nameID;
                dataForm.req  = "close";
                dataForm.text = "연결을 종료합니다.";
                string request = JsonConvert.SerializeObject(dataForm);
                byte[] bDts    = Encoding.UTF8.GetBytes(request);
                // Encoding.UTF8.GetBytes(nameID + '`' + tts);


                // 서버에 전송한다.
                mainSock.Send(bDts);

                // 전송 완료 후 텍스트박스에 추가하고, 원래의 내용은 지운다.
                AppendText(txtHistory, string.Format("[연결을 종료합니다.]"));

                mainSock        = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                btnConnect.Text = "연결";
                return;
            }
            if (mainSock.Connected)
            {
                MsgBoxHelper.Error("이미 연결되어 있습니다!");
                return;
            }



            if (txtID.Text.Length <= 0)
            {
                MsgBoxHelper.Error("아이디를 입력해주세요");
            }
            nameID = txtID.Text; //ID

            AppendText(txtHistory, string.Format("서버: @{0}, port: @{1}, ID: @{2}", txtAddress.Text, port, nameID));
            try
            {
                // 여기서 브로드 캐스트 한번 해줘야 함
                mainSock.Connect(serverIPAddress, port);
                // 밑에는 원래 코드
                // mainSock.Connect(broadcastIPAddresses[192], port);
                //Console.WriteLine("이거 보이면 연결 잘 된겨 브로드 캐스트 아이피 뽑기 : "+broadcastIPAddress  + i);
            }
            catch (Exception ex)
            {
                Console.WriteLine("연결 실패 ");
                MsgBoxHelper.Error("연결에 실패했습니다!\n오류 내용: {0}", MessageBoxButtons.OK, ex.Message);
            }
            // 연결 완료되었다는 메세지를 띄워준다.
            AppendText(txtHistory, "서버와 연결되었습니다.");

            // 연결 완료, 서버에서 데이터가 올 수 있으므로 수신 대기한다.
            AsyncObject obj = new AsyncObject(4096);

            obj.WorkingSocket = mainSock;
            mainSock.BeginReceive(obj.Buffer, 0, obj.BufferSize, 0, DataReceived, obj);
        }