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;
using System.IO;
namespace PDMS_TCG
{
public partial class FormHost : Form
{
public FormHost()
{
InitializeComponent();
}
private void btnConnect_Click(object sender, EventArgs e)
{
{
IPAddress ipAd = IPAddress.Parse(txtAddress.Text);
TcpListener myList = new TcpListener(ipAd, int.Parse(txtPort.Text));
myList.Start();
Socket s = myList.AcceptSocket();
RPS rps = new RPS();
rps.Show();
}
}
private void btnHost_Click(object sender, EventArgs e)
{
IPAddress ipAd = IPAddress.Parse(GV.strAddress);
TcpListener myList = new TcpListener(ipAd, int.Parse(txtPort.Text));
myList.Start();
Socket s = myList.AcceptSocket();
}
}
}
txtAddress = 主机的 IP 地址
txtPort = 端口号
我对 TcpListener/Sockets 有一些困惑。有人可以帮我修复这段代码吗?单击 btnHost 让您托管连接,然后 btnConnect 连接到主机。此外,一旦连接,我怎样才能让 1 个事件触发另一台计算机上的事件?