别怕还有我在吧 关注:11贴子:455
  • 1回复贴,共1

为什么连接自己的端口就能成功,连接别人的就不行啊,求大神讲解

只看楼主收藏回复


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 NO32
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TcpListener tcplistener = null;
IPAddress ipaddress = IPAddress.Parse(textBox1.Text);
int port = Convert.ToInt32(textBox2.Text);
tcplistener = new TcpListener(ipaddress,port);
tcplistener.Start();
richTextBox1.Text = "等待链接....\n";
TcpClient tcpclient = null;
if (tcplistener.Pending())
tcpclient = tcplistener.AcceptTcpClient();
else
tcpclient = new TcpClient(textBox1.Text, port);
richTextBox1.Text += "链接成功\n";
tcpclient.Close();
tcplistener.Stop();
}
}
}


IP属地:北京1楼2014-08-23 17:35回复
    車 涅槃


    IP属地:北京2楼2014-10-27 07:02
    回复