Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#通过将多个TCP客户端的接收数据显示到Datagrid中,来处理TCP服务器上的多个TCP客户端的接收数据_C#_Wpf_Sockets_Tcp_Datagrid - Fatal编程技术网

C#通过将多个TCP客户端的接收数据显示到Datagrid中,来处理TCP服务器上的多个TCP客户端的接收数据

C#通过将多个TCP客户端的接收数据显示到Datagrid中,来处理TCP服务器上的多个TCP客户端的接收数据,c#,wpf,sockets,tcp,datagrid,C#,Wpf,Sockets,Tcp,Datagrid,我开发了一个基于C#的TCP服务器GUI应用程序,它接受来自多个TCP客户端的数据 void m_Terminal_MessageRecived(Socket socket, byte[] buffer) { string message = ConvertBytesToString(buffer, buffer.Length); PublishMessage(listMessages, string.Format("Socket

我开发了一个基于C#的TCP服务器GUI应用程序,它接受来自多个TCP客户端的数据

void m_Terminal_MessageRecived(Socket socket, byte[] buffer)
        {
            string message = ConvertBytesToString(buffer, buffer.Length);

            PublishMessage(listMessages, string.Format("Sockets: {0}", message));

            // Send Echo
           // m_ServerTerminal.DistributeMessage(buffer);
        }


        private string ConvertBytesToString(byte[] bytes, int iRx)
        {
            char[] chars = new char[iRx + 1];
            System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
            d.GetChars(bytes, 0, iRx, chars, 0);
            string szData = new string(chars);

            return szData;
        }
我从TCP客户端接收的数据是32位数据。在我的应用程序中,多个TCP客户端数据如下所示:

0001233110002523000124510321562(来自1个客户)

011125631100251245012451032125等等

现在,我希望TCP客户机的数据首先被解析为4位,并显示在(比如)datagrid的8列(32/4=8)中,因为每4位代表TCP客户机的一些特征。对于datagrid第二行上的下一个TCP客户端,同样的事情也应该起作用

你能给我一些建议或一个例子来说明这一点吗?任何帮助都将不胜感激。先谢谢你

下面是我从多个TCP客户端接收数据的代码

void m_Terminal_MessageRecived(Socket socket, byte[] buffer)
        {
            string message = ConvertBytesToString(buffer, buffer.Length);

            PublishMessage(listMessages, string.Format("Sockets: {0}", message));

            // Send Echo
           // m_ServerTerminal.DistributeMessage(buffer);
        }


        private string ConvertBytesToString(byte[] bytes, int iRx)
        {
            char[] chars = new char[iRx + 1];
            System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
            d.GetChars(bytes, 0, iRx, chars, 0);
            string szData = new string(chars);

            return szData;
        }

如果没有定义列的数据网格,请首先添加列

for (int iIndex = 1; iIndex <= 8; iIndex++)
{
     DataColumn col = new DataGridTextColumn();
     col.Header = iIndex;
     col.Binding = new Binding(iIndex);
     YourDatagrid.Columns.Add(col);
}

0001233100025123000124510321562包含的信息超过32位,因此您的描述没有多大意义。另外,您的问题似乎是关于显示信息,但您所显示的只是接收数据的代码。请提供到目前为止您已经尝试过的具体内容,并准确解释该代码的功能以及与您希望它执行的功能的不同之处。如果您将其计算在内,则为32位数据。不要看那些数字。我问过显示数据的问题,所以我把它贴在了这里。如果我知道的话,我就不会在这里发帖了。这就是我发布的代码,通过它我可以接收数据。你知道吗?请阅读我在上一篇评论中提供的链接,以及这篇评论:。嗯。。谢谢你的链接。谢谢。。我现在就要经历这一切。