udp服务器

扫码查看
本文介绍了udp服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
伙计们,我刚刚构建了一个简单的udp服务器,那就是代码:


Hello every one ,
Guys I just built a simple udp server and that''s the code :


private void Form1_Load(object sender, EventArgs e)
        {
            Thread thdUDPServer = new Thread(new
ThreadStart(serverThread));
            thdUDPServer.Start();
        }

        public void serverThread()
{
UdpClient udpClient = new UdpClient(8080);
while(true)
{
    IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
    Byte[] receiveBytes = udpClient.Receive(ref
RemoteIpEndPoint);
    string returnData = Encoding.ASCII.GetString(receiveBytes);
    lbConnections.Items.Add(
    RemoteIpEndPoint.Address.ToString() + ":" +
    returnData.ToString()
    );
}
}
    }
}



但是每次我运行程序时,都会出现以下错误:

跨线程操作无效:从创建该线程的线程之外的线程访问控件"lbConnections".

所以请帮助我



But every time when i run the program the following error appears:

Cross-thread operation not valid: Control ''lbConnections'' accessed from a thread other than the thread it was created on.

so please help me

推荐答案


这篇关于udp服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 21:31
查看更多