public void Connect(string ipAddress, int port) { SubscribeEvents(); try { _sender.Connect(IPAddress.Parse(ipAddress), port); _sender.WaitMessage(); } catch (Exception ex) { OnException?.Invoke(this, ex); } }
// 注意这个事件 //public event PortNumberReadyEventHandler PortNumberReady //{ // add // { // ((MessageReceiver)receiver).PortNumberReady += value; // } // remove // { // ((MessageReceiver)receiver).PortNumberReady -= value; // } //} // 连接远程 - 使用主机名 public bool ConnectByHost(string hostName, int port) { IPAddress[] ips = Dns.GetHostAddresses(hostName); return(sender.Connect(ips[0], port) && fileSender.Connect(ips[0], port + 1)); }
public bool ConnectByIp(IPAddress ip, int port) { return(sender.Connect(ip, port)); }