private void RegisterBt_Click(object sender, EventArgs e)
        {
            registerBt.Enabled = false;
            socket             = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var Register = new JObject();

            Register.Add("req", "register");
            Register.Add("id", id.Text);
            Register.Add("pw", pw.Text);

            byte[] registerData = Encoding.UTF8.GetBytes(Register.ToString());

            try
            {
                socket.Connect(IPAddress.Parse("192.168.1.186"), 9000);
            }
            catch (Exception ex)
            {
                MsgBoxHelper.Error("연결에 실패했습니다!\n오류 내용:{0}", MessageBoxButtons.OK, ex.Message);
            }

            if (!socket.IsBound)
            {
                MsgBoxHelper.Warn("서버가 실행되고 있지 않습니다!");
                return;
            }


            AsyncObject obj = new AsyncObject(4096);

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

            socket.Send(registerData);
        }
Exemple #2
0
        private void OnSendData(object sender, EventArgs e)
        {
            if (!mainSock.IsBound)
            {
                MsgBoxHelper.Warn("서버가 실행되고 있지 않습니다!");
                return;
            }

            string tts = input.Text.Trim();

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

            byte[] bDts = Encoding.UTF8.GetBytes(tts);

            mainSock.Send(bDts);

            input.Clear();
        }