可發資料,但服務器埠不接收資料,監聽也報錯(使用本地ip埠能夠實作資料收發)
try
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(IPAddress.Parse(textBox1.Text), Int32.Parse(textBox2.Text));
NetworkStream ns = tcpClient.GetStream();
if (ns.CanWrite)
{
Byte[] sendBytes = Encoding.Default.GetBytes(richTextBox2.Text);
ns.Write(sendBytes, 0, sendBytes.Length);
tcpClient.Close();
ns.Close();
}
else
{
MessageBox.Show("不能寫入資料流");
tcpClient.Close();
ns.Close();
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/55395.html
標籤:C#
