private void tcp_send(string data)//tcp协议转发数据
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(IPAddress.Parse("127.0.0.1"), 8000);//发送的主机地址及端口
NetworkStream ntwStream = tcpClient.GetStream();
if (ntwStream.CanWrite)
{
Byte[] bytSend = Encoding.UTF8.GetBytes(data);
ntwStream.Write(bytSend, 0, bytSend.Length);
}
else
{
ntwStream.Close();
tcpClient.Close();

return;
}

ntwStream.Close();
tcpClient.Close();
}

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2021-11-26
  • 2022-02-20
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
  • 2021-11-14
  • 2021-09-04
相关资源
相似解决方案