TcpClient クラスとメソッドを介してデバイスからデータを読み取ることができるのは以下のとおりです。
データのバイトを読み取ることができるイーサネット接続を介して、Ipaddressとポートを使用して接続を確立したら。私の読み取りメソッドは、特定のバイト数のネットワークストリームデータを読み取り、必要に応じて文字列をトリミングし、データベースに更新し、更新されたデータをdatagridviewに表示しようとします.datagridviewにデータは表示されません.
誰でもこれを行う方法を提案できますか?
追加されたコード:
private void ReceiveMethod()
{
try
{
string IP1 = textIP.Text.Trim();
string port1 = textPort.Text.Trim();
int port = Convert.ToInt32(port1);
NetworkStream ns;
int bytesRead = 0;
byte[] buffer = new byte[9];
try
{
IPAddress ipAddress = System.Net.IPAddress.Parse(Ip1);
client = new TcpClient();
client.Connect(IP1, port);
while (true)
{
ns = client.GetStream();
ns.Read(buffer, (int)bytesRead, buffer.Length - (int)bytesRead);
ASCIIEncoding encoder = new ASCIIEncoding();
msg = encoder.GetString(buffer);
GetData(msg);
}
client.Close();
}
GetData(string data)
{
I'm trimming the data value according to my need
and the updateing one filed of db and trying to populate table data in gridview
//if i remove the while(true) in the Receivemethod am able to view the data in
datagridview but i want to read continuous data from network stream and want
to show updated data in datagrid view
}