菜鸟 求助C# tcp connect连接问题
用TCP出现的问题,求助
服务端
private void Form1_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(ListenerThread));
t.IsBackground = true;
t.Start();
}
private void ListenerThread()
{
try
{
tcpListener = new TcpListener(new IPEndPoint(IPAddress.Parse("192.168.2.92"), 12000));
tcpListener.Start();
this.Invoke((EventHandler)delegate
{
listBox1.Items.Add("正在监听12000端口");
});
while (true)
{
TcpClient tcpClient = tcpListener.AcceptTcpClient();
IPEndPoint ep = (IPEndPoint)tcpClient.Client.RemoteEndPoint;
this.Invoke((EventHandler)delegate
{
listBox1.Items.Add("有客户端连接成功!");
string ip = ep.Address.ToString();
int port = ep.Port;
listBox1.Items.Add("IP:" + ip + ",端口" + port.ToString());
});
NetworkStream netStream = tcpClient.GetStream();
StreamWriter writer = new StreamWriter(netS