嗨,我使用的TcpClient和TCPlitner来传输数据,但我得到的错误不低于连接 是我的代码因为目标机器主动拒绝,所以无法建立连接?
private void button1_Click(object sender, EventArgs e)
{
TcpClient tcpc = new TcpClient("192.168.21.46", 10);
NetworkStream nts = tcpc.GetStream();
if (nts.CanWrite)
{
Byte[] sends = System.Text.Encoding.ASCII.GetBytes(textBox1.Text.ToCharArray());
nts.Write(sends, 0, sends.Length);
nts.Flush();
}
}
private void button2_Click(object sender, EventArgs e)
{
TcpListener myListener = new TcpListener(10);
myListener.Start();
while (true)
{
//Accept a new connection
Socket mySocket = myListener.AcceptSocket();
if (mySocket.Connected)
{
//make a byte array and receive data from the client
Byte[] receive = new Byte[64];
int i = mySocket.Receive(receive, receive.Length, 0);
char[] unwanted = { ' ', ' ', ' ' };
string rece = System.Text.Encoding.ASCII.GetString(receive);
label1.Text = rece.TrimEnd(unwanted);
}
}
}
这两个按钮,我在其中提到的相同的形式和IP apddress增加了我系统IP地址。谁能告诉我为什么发生这种情况。即使我也删除防火墙设置。
你在同一时间按下两个按钮,或者我不明白的东西... – Cynede
是目标机器上的端口免费供您使用? – MrFox
@Heather一键点击连接插座,然后传送和第二个按钮recive数据 – Jankya