基本信息
源码名称:Socket简易版,客户端和服务端互联,实现信息收发
源码大小:40.33M
文件格式:.zip
开发语言:C#
更新时间:2021-03-29
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

超简单的实现服务端和客户端的收发,实现信息接受发送,简单易懂,无复杂代码

/// <summary>
        /// 接受客户端信息
        /// </summary>
        public void ReciveMsg()
        {
            Socket socketClient = default(Socket);
            socketClient = socketServer.Accept();    //返回通信套接字
            while (true)
            {
                Byte[] buffer = new byte[1024];
                int len = socketClient.Receive(buffer);
                string GetMsg = Encoding.UTF8.GetString(buffer,0, len);
                txtReceive.BeginInvoke(new Action(() => { 
                txtReceive.Text = GetMsg;
                }));
                socketClient.Send(Encoding.UTF8.GetBytes("收到客户端的信息"));
            }
        }

/// <summary>
        /// 接受客户端信息
        /// </summary>
        public void ReciveMsg()
        {
            while (true)
            {
                Byte[] buffer = new byte[1024];
                int len = socket.Receive(buffer);
                string GetMsg = Encoding.UTF8.GetString(buffer, 0, len);
                textEdit1.BeginInvoke(new Action(() => {
                    textEdit1.Text = GetMsg;
                }));
            }
        }