Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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# 在客户端之间发送消息(套接字UDP)_C#_Sockets - Fatal编程技术网

C# 在客户端之间发送消息(套接字UDP)

C# 在客户端之间发送消息(套接字UDP),c#,sockets,C#,Sockets,我是C#新手,正在练习Socket编程 首先,我为客户端创建了一个服务器连接到它 服务器: class Program { static void Main(string[] args) { int recv; byte[] data = new byte[1024]; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 1900); Socket newsock = new S

我是C#新手,正在练习Socket编程

首先,我为客户端创建了一个服务器连接到它

服务器:

class Program {
    static void Main(string[] args) {
        int recv;
        byte[] data = new byte[1024];
        IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 1900);

        Socket newsock = new Socket(AddressFamily.InterNetwork,
                            SocketType.Dgram, ProtocolType.Udp);

        newsock.Bind(ipep);
        Console.WriteLine("Waiting for a client...");

        IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
        EndPoint Remote = (EndPoint)(sender);

        recv = newsock.ReceiveFrom(data, ref Remote);

        Console.WriteLine("Message received from {0}:", Remote.ToString());
        Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));

        string welcome = "Welcome to my test server";
        data = Encoding.ASCII.GetBytes(welcome);
        newsock.SendTo(data, data.Length, SocketFlags.None, Remote);

        while (true) {
            data = new byte[1024];
            recv = newsock.ReceiveFrom(data, ref Remote);

            Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
            newsock.SendTo(data, recv, SocketFlags.None, Remote);
        }
    }
}
客户:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;

namespace serverUDPWF {
    public partial class ServerForm : Form {
        byte[] data = new byte[30];
        string input = "";
        string stringData = "";
        IPEndPoint iep,sender;
        Socket server;
        string welcome = "";
        int recv;
        EndPoint tmpRemote;

        public ServerForm() {
            InitializeComponent();
            startServer();
        }

        public void startServer() {
            iep = new IPEndPoint(
            IPAddress.Parse("127.0.0.1"), 1900);

            server = new Socket(AddressFamily.InterNetwork,
                           SocketType.Dgram, ProtocolType.Udp);

            welcome = "Hello, are you there?";
            data = Encoding.ASCII.GetBytes(welcome);
            server.SendTo(data, data.Length, SocketFlags.None, iep);

            sender = new IPEndPoint(IPAddress.Any, 0);
            tmpRemote = (EndPoint)sender;

            data = new byte[30];
            recv = server.ReceiveFrom(data, ref tmpRemote);
            Console.WriteLine();

            listBox1.Items.Add("Message received from {0}:"  +  tmpRemote.ToString());
            listBox1.Items.Add(Encoding.ASCII.GetString(data, 0, recv));
        }

        private void sendMessageToserver(object sender, EventArgs e) {
            if (textBox2.Text == "") {
                MessageBox.Show("Please Enter Your Name");
            }
            else {
                int i = 30;

                input = textBox2.Text + ": " + textBox1.Text;

                if (input == "exit") {
                    this.Close();
                }
                server.SendTo(Encoding.ASCII.GetBytes(input), tmpRemote);
                textBox1.Text = "";
                data = new byte[i];

                try {
                    recv = server.ReceiveFrom(data, ref tmpRemote);
                    stringData = Encoding.ASCII.GetString(data, 0, recv);
                    listBox1.Items.Add(stringData);                        
                }
                catch (SocketException) {
                    listBox1.Items.Add("WARNING: data lost, retry message.");
                    i += 10;
                }
            }
        }   
    }
}
我的问题是如何使客户端不需要像127.0.0.1那样输入服务器ip地址。我的第二个问题是我同时打开了两个客户端,但是客户端A向服务器发送了一条消息,但是客户端B没有从客户端A接收到消息(我想发送一条广播类型的消息)


我如何才能做到这一点?

多播udp通信。。我只是想尝试一下,如果有什么不对劲,请随意分享

客户端:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Threading;

namespace Myclient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }
        Socketsending socketsending;

        string multicastIP = string.Empty;
        int multicastPort = 0;
        int clientPort = 0;
        string clientSysname = string.Empty;
        string Nodeid = string.Empty;
        string clientIP = string.Empty;
        string recievedText = string.Empty;
        string sendingText = string.Empty;

        IPAddress ipAddress;
        IPEndPoint ipEndpoint;
        UdpClient udpClient;


        string[] splitRecievedText;

        byte[] byteRecieve;

        private void Form1_Load(object sender, EventArgs e)
        {

            Random _random = new Random();

            multicastIP = "224.5.6.7";
            multicastPort = 5000;
            Nodeid = "node" + _random.Next(1000, 9999);
            clientPort = _random.Next(1000, 9999);
            clientSysname = Dns.GetHostName();

            ipAddress = Dns.GetHostEntry(clientSysname).AddressList.FirstOrDefault
                (addr => addr.AddressFamily.Equals(AddressFamily.InterNetwork));
            ipEndpoint = new IPEndPoint(ipAddress, clientPort);
            clientIP = ipAddress.ToString();

            label1.Text = "Node id: " + Nodeid;
            label2.Text = "Host Name: " + clientSysname;

            Thread threadMain = new Thread(connect);
            threadMain.Start();

            threadMain = new Thread(receive);
            threadMain.Start();

        }
        void connect()
        {
            socketsending = new Socketsending();


            sendingText = "connect@" + clientSysname + "#" + clientIP + "#" + clientPort + "#" + Nodeid + "#";

            socketsending.send(multicastIP, multicastPort, sendingText);

        }
        void receive()
        {
            udpClient = new UdpClient(clientPort);

            while (true)
            {
                IPEndPoint _ipendpoint = null;
                byteRecieve = udpClient.Receive(ref _ipendpoint);

                recievedText = Encoding.ASCII.GetString(byteRecieve);
                splitRecievedText = recievedText.Split('@');

                if (splitRecievedText[0] == "stop")
                {

                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sendingText = "message@" + Nodeid + '$' + textBox1.Text + '$';
            socketsending.send(multicastIP, multicastPort, sendingText);

        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.Collections;
namespace Myserver
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        string multicastip = string.Empty;
        string serversystemname = string.Empty;
        string receiveddata = string.Empty;
        string nodeinfo = string.Empty;
        string clientHostName = string.Empty;
        string clientIP = string.Empty;
        string Nodeid = string.Empty;

        int multicastport = 0;
        int clientport = 0;

        DataTable datatable;
        DataTable dataTableAddRemove;

        string[] splitReceived;
        string[] splitnodeinfo;

        Socket socket;
        IPAddress ipaddress;
        IPEndPoint ipendpoint;

        byte[] bytereceive;

        Dictionary<string, string> dictionarytable;

        public delegate void updategrid();

        private void Form1_Load(object sender, EventArgs e)
        {
            multicastip = "224.5.6.7";
            multicastport = 5000;
            serversystemname = Dns.GetHostName();
            datatable = new DataTable();
            datatable.Columns.Add("HostName");
            datatable.Columns.Add("Nodeid");
            datatable.Columns.Add("ipaddress");
            datatable.Columns.Add("portnumber");
            DGV.DataSource = datatable;

            Thread threadreceive = new Thread(receiver);
            threadreceive.Start();
        }

        void receiver()
        {
            dictionarytable = new Dictionary<string, string>();

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            ipendpoint = new IPEndPoint(IPAddress.Any, multicastport);
            socket.Bind(ipendpoint);
            ipaddress = IPAddress.Parse(multicastip);
            socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ipaddress, IPAddress.Any));

            while (true)
            {
                bytereceive = new byte[4200];
                socket.Receive(bytereceive);
                receiveddata = Encoding.ASCII.GetString(bytereceive, 0, bytereceive.Length);

                splitReceived = receiveddata.Split('@');

                if (splitReceived[0].ToString() == "connect")
                {
                    nodeinfo = splitReceived[1].ToString();

                    connect();
                }
                else if (splitReceived[0].ToString() == "Disconnect")
                {
                    nodeinfo = splitReceived[1].ToString();

                    Thread threadDisconnect = new Thread(disconnect);
                    threadDisconnect.Start();
                }
                else if (splitReceived[0].ToString() == "message")
                {
                    string[] str = splitReceived[1].Split('$');

                    listBox1.Items.Add(str[0] + " -> " + str[1]);
                }
            }
        }
        void connect()
        {
            SocketSending socketsending = new SocketSending();

            int count = 0;

            splitnodeinfo = nodeinfo.Split('#');

            clientHostName = splitnodeinfo[0].ToString();
            clientIP = splitnodeinfo[1].ToString();
            clientport = Convert.ToInt32(splitnodeinfo[2].ToString());
            Nodeid = splitnodeinfo[3].ToString();

            if (!dictionarytable.ContainsKey(Nodeid))
            {
                count++;

                dictionarytable.Add(Nodeid, clientIP + "#" + clientport + "#" + clientHostName);

                dataTableAddRemove = (DataTable)DGV.DataSource;
                DataRow dr = dataTableAddRemove.NewRow();

                dr["Nodeid"] = Nodeid;
                dr["HostName"] = clientHostName;
                dr["IPAddress"] = clientIP;
                dr["portNumber"] = clientport;

                dataTableAddRemove.Rows.Add(dr);
                datatable = dataTableAddRemove;

                updatenodegrid();
            }
        }
        void disconnect()
        {
            SocketSending socketsending = new SocketSending();

            string removeClient = string.Empty;
            splitnodeinfo = nodeinfo.Split('#');
            clientHostName = splitnodeinfo[0].ToString();
            Nodeid = splitnodeinfo[1].ToString();

            dataTableAddRemove = (DataTable)DGV.DataSource;
            DataRow[] arrayDataRow = dataTableAddRemove.Select();

            for (int i = 0; i < arrayDataRow.Length; i++)
            {
                string matchGridHostName = arrayDataRow[i]["HostName"].ToString();
                if (clientHostName == matchGridHostName)
                {
                    Thread.Sleep(100);

                    removeClient = clientHostName;
                    arrayDataRow[i].Delete();
                    break;
                }
            }
            if (dictionarytable.ContainsKey(removeClient))
            {
                dictionarytable.Remove(removeClient);
            }
        }
        void updatenodegrid()
        {
            if (this.DGV.InvokeRequired)
                this.DGV.Invoke(new updategrid(updatenodegrid));
            else
                DGV.DataSource = datatable;
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            dictionarytable.Clear();
        }
    }
}
服务器:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Threading;

namespace Myclient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }
        Socketsending socketsending;

        string multicastIP = string.Empty;
        int multicastPort = 0;
        int clientPort = 0;
        string clientSysname = string.Empty;
        string Nodeid = string.Empty;
        string clientIP = string.Empty;
        string recievedText = string.Empty;
        string sendingText = string.Empty;

        IPAddress ipAddress;
        IPEndPoint ipEndpoint;
        UdpClient udpClient;


        string[] splitRecievedText;

        byte[] byteRecieve;

        private void Form1_Load(object sender, EventArgs e)
        {

            Random _random = new Random();

            multicastIP = "224.5.6.7";
            multicastPort = 5000;
            Nodeid = "node" + _random.Next(1000, 9999);
            clientPort = _random.Next(1000, 9999);
            clientSysname = Dns.GetHostName();

            ipAddress = Dns.GetHostEntry(clientSysname).AddressList.FirstOrDefault
                (addr => addr.AddressFamily.Equals(AddressFamily.InterNetwork));
            ipEndpoint = new IPEndPoint(ipAddress, clientPort);
            clientIP = ipAddress.ToString();

            label1.Text = "Node id: " + Nodeid;
            label2.Text = "Host Name: " + clientSysname;

            Thread threadMain = new Thread(connect);
            threadMain.Start();

            threadMain = new Thread(receive);
            threadMain.Start();

        }
        void connect()
        {
            socketsending = new Socketsending();


            sendingText = "connect@" + clientSysname + "#" + clientIP + "#" + clientPort + "#" + Nodeid + "#";

            socketsending.send(multicastIP, multicastPort, sendingText);

        }
        void receive()
        {
            udpClient = new UdpClient(clientPort);

            while (true)
            {
                IPEndPoint _ipendpoint = null;
                byteRecieve = udpClient.Receive(ref _ipendpoint);

                recievedText = Encoding.ASCII.GetString(byteRecieve);
                splitRecievedText = recievedText.Split('@');

                if (splitRecievedText[0] == "stop")
                {

                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sendingText = "message@" + Nodeid + '$' + textBox1.Text + '$';
            socketsending.send(multicastIP, multicastPort, sendingText);

        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.Collections;
namespace Myserver
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        string multicastip = string.Empty;
        string serversystemname = string.Empty;
        string receiveddata = string.Empty;
        string nodeinfo = string.Empty;
        string clientHostName = string.Empty;
        string clientIP = string.Empty;
        string Nodeid = string.Empty;

        int multicastport = 0;
        int clientport = 0;

        DataTable datatable;
        DataTable dataTableAddRemove;

        string[] splitReceived;
        string[] splitnodeinfo;

        Socket socket;
        IPAddress ipaddress;
        IPEndPoint ipendpoint;

        byte[] bytereceive;

        Dictionary<string, string> dictionarytable;

        public delegate void updategrid();

        private void Form1_Load(object sender, EventArgs e)
        {
            multicastip = "224.5.6.7";
            multicastport = 5000;
            serversystemname = Dns.GetHostName();
            datatable = new DataTable();
            datatable.Columns.Add("HostName");
            datatable.Columns.Add("Nodeid");
            datatable.Columns.Add("ipaddress");
            datatable.Columns.Add("portnumber");
            DGV.DataSource = datatable;

            Thread threadreceive = new Thread(receiver);
            threadreceive.Start();
        }

        void receiver()
        {
            dictionarytable = new Dictionary<string, string>();

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            ipendpoint = new IPEndPoint(IPAddress.Any, multicastport);
            socket.Bind(ipendpoint);
            ipaddress = IPAddress.Parse(multicastip);
            socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ipaddress, IPAddress.Any));

            while (true)
            {
                bytereceive = new byte[4200];
                socket.Receive(bytereceive);
                receiveddata = Encoding.ASCII.GetString(bytereceive, 0, bytereceive.Length);

                splitReceived = receiveddata.Split('@');

                if (splitReceived[0].ToString() == "connect")
                {
                    nodeinfo = splitReceived[1].ToString();

                    connect();
                }
                else if (splitReceived[0].ToString() == "Disconnect")
                {
                    nodeinfo = splitReceived[1].ToString();

                    Thread threadDisconnect = new Thread(disconnect);
                    threadDisconnect.Start();
                }
                else if (splitReceived[0].ToString() == "message")
                {
                    string[] str = splitReceived[1].Split('$');

                    listBox1.Items.Add(str[0] + " -> " + str[1]);
                }
            }
        }
        void connect()
        {
            SocketSending socketsending = new SocketSending();

            int count = 0;

            splitnodeinfo = nodeinfo.Split('#');

            clientHostName = splitnodeinfo[0].ToString();
            clientIP = splitnodeinfo[1].ToString();
            clientport = Convert.ToInt32(splitnodeinfo[2].ToString());
            Nodeid = splitnodeinfo[3].ToString();

            if (!dictionarytable.ContainsKey(Nodeid))
            {
                count++;

                dictionarytable.Add(Nodeid, clientIP + "#" + clientport + "#" + clientHostName);

                dataTableAddRemove = (DataTable)DGV.DataSource;
                DataRow dr = dataTableAddRemove.NewRow();

                dr["Nodeid"] = Nodeid;
                dr["HostName"] = clientHostName;
                dr["IPAddress"] = clientIP;
                dr["portNumber"] = clientport;

                dataTableAddRemove.Rows.Add(dr);
                datatable = dataTableAddRemove;

                updatenodegrid();
            }
        }
        void disconnect()
        {
            SocketSending socketsending = new SocketSending();

            string removeClient = string.Empty;
            splitnodeinfo = nodeinfo.Split('#');
            clientHostName = splitnodeinfo[0].ToString();
            Nodeid = splitnodeinfo[1].ToString();

            dataTableAddRemove = (DataTable)DGV.DataSource;
            DataRow[] arrayDataRow = dataTableAddRemove.Select();

            for (int i = 0; i < arrayDataRow.Length; i++)
            {
                string matchGridHostName = arrayDataRow[i]["HostName"].ToString();
                if (clientHostName == matchGridHostName)
                {
                    Thread.Sleep(100);

                    removeClient = clientHostName;
                    arrayDataRow[i].Delete();
                    break;
                }
            }
            if (dictionarytable.ContainsKey(removeClient))
            {
                dictionarytable.Remove(removeClient);
            }
        }
        void updatenodegrid()
        {
            if (this.DGV.InvokeRequired)
                this.DGV.Invoke(new updategrid(updatenodegrid));
            else
                DGV.DataSource = datatable;
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            dictionarytable.Clear();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
Net系统;
使用System.Net.Sockets;
使用系统线程;
使用System.IO;
使用系统集合;
名称空间Myserver
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
CheckForIllegalCrossThreadCalls=false;
}
string multicastip=string.Empty;
string serversystemname=string.Empty;
string receiveddata=string.Empty;
string nodeinfo=string.Empty;
string clientHostName=string.Empty;
string clientIP=string.Empty;
string Nodeid=string.Empty;
int多播端口=0;
int clientport=0;
数据表数据表;
DataTable dataTableAddRemove;
接收到字符串[];
字符串[]splitnodeinfo;
插座;
IPAddress-IPAddress;
IPEndPoint-IPEndPoint;
字节[]bytereceive;
字典表;
公共委托void updategrid();
私有void Form1\u加载(对象发送方、事件参数e)
{
multicastip=“224.5.6.7”;
多播端口=5000;
serversystemname=Dns.GetHostName();
datatable=新的datatable();
datatable.Columns.Add(“主机名”);
datatable.Columns.Add(“Nodeid”);
datatable.Columns.Add(“ipaddress”);
datatable.Columns.Add(“端口号”);
DGV.DataSource=数据表;
Thread threadreceive=新线程(接收器);
threadreceive.Start();
}
无效接收人()
{
dictionarytable=新字典();
套接字=新套接字(AddressFamily.InterNetwork、SocketType.Dgram、ProtocolType.Udp);
ipendpoint=新ipendpoint(IPAddress.Any,多播端口);
套接字绑定(ipendpoint);
ipaddress=ipaddress.Parse(multicastip);
socket.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.AddMembership,新的MulticastOption(ipaddress,ipaddress.Any));
while(true)
{
bytereceive=新字节[4200];
socket.Receive(bytereceive);
receiveddata=Encoding.ASCII.GetString(bytereceive,0,bytereceive.Length);
splitReceived=receiveddata.Split('@');
如果(splitReceived[0].ToString()=“connect”)
{
nodeinfo=splitReceived[1]。ToString();
connect();
}
else if(splitReceived[0]。ToString()=“断开”)
{
nodeinfo=splitReceived[1]。ToString();
螺纹断开=新螺纹(断开);
threadDisconnect.Start();
}
else if(splitReceived[0].ToString()=“消息”)
{
字符串[]str=splitReceived[1]。拆分(“$”);
listBox1.Items.Add(str[0]+“->”+str[1]);
}
}
}
void connect()
{
SocketSending SocketSending=新建SocketSending();
整数计数=0;
splitnodeinfo=nodeinfo.Split(“#”);
clientHostName=splitnodeinfo[0].ToString();
clientIP=splitnodeinfo[1].ToString();
clientport=Convert.ToInt32(splitnodeinfo[2].ToString());
Nodeid=splitnodeinfo[3].ToString();
如果(!dictionarytable.ContainsKey(Nodeid))
{
计数++;
添加(Nodeid,clientIP+“#”+clientport+“#”+clientHostName);
dataTableAddRemove=(DataTable)DGV.DataSource;
DataRow dr=dataTableAddRemove.NewRow();
dr[“Nodeid”]=Nodeid;
dr[“HostName”]=clientHostName;
dr[“IPAddress”]=clientIP;
dr[“端口号”]=客户端端口;
dataTableAddRemove.Rows.Add(dr);
datatable=dataTableAddRemove;
updatenodegrid();
}
}
无效断开连接()
{
SocketSending SocketSending=新建SocketSending();
string removeClient=string.Empty;
splitnodeinfo=nodeinfo.Split(“#”);
clientHostName=splitnodeinfo[0].ToString();
Nodeid=splitnodeinfo[1].ToString();
dataTableAddRemove=(DataTable)DGV.DataSource;
DataRow[]arrayDataRow=dataTableAddRemove.Select();
for(int i=0;i