void DataReceived(IAsyncResult ar)
        {
            AsyncObject obj = (AsyncObject)ar.AsyncState;

            try
            {
                int received = obj.WorkingSocket.EndReceive(ar);

                if (received <= 0)
                {
                    obj.WorkingSocket.Close();
                    Application.Exit();
                    return;
                }

                string data     = Encoding.UTF8.GetString(obj.Buffer);
                var    readJson = JObject.Parse(data);
                onlineList.Items.Clear();
                foreach (var item in readJson["result"])
                {
                    SetListView(onlineList, item.ToString());
                }

                obj.ClearBuffer();

                obj.WorkingSocket.BeginReceive(obj.Buffer, 0, 4096, 0, DataReceived, obj);
            }
            catch
            {
                SetFormClose(this);
            }
        }
Example #2
0
        void DataReceived(IAsyncResult ar)
        {
            AsyncObject obj      = (AsyncObject)ar.AsyncState;
            int         received = obj.WorkingSocket.EndReceive(ar);

            if (received <= 0)
            {
                obj.WorkingSocket.Close();
                return;
            }

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

            AppendText(chat, string.Format("[받음] {0}", text));

            obj.ClearBuffer();

            obj.WorkingSocket.BeginReceive(obj.Buffer, 0, 4096, 0, DataReceived, obj);
        }