private void mnuConnect_Click(object sender, EventArgs e) { Connect _connect = new Connect(m_node); _connect.ShowDialog(); if (_connect.DialogResult == DialogResult.Cancel) { m_log.Add("User selected cancel"); _connect.Dispose(); return; } MEETIPEndPoint ipepLoc = _connect.MipLocalEndPoint; MEETIFace iface = (MEETIFace)m_node.IFaces[ipepLoc.Address]; if (iface == null) { iface = new MEETIFace(ipepLoc.Address.ToString(), ipepLoc.Address, m_node); m_node.IFaces[ipepLoc.Address] = iface; } MEETIPEndPoint ipepRem = _connect.MipRemoteEndPoint; // create connection MEETPCQueue inQ = new MEETPCQueue(); MEETPCQueue outQ = new MEETPCQueue(); MEETSockConnection conn = new MEETSockConnection(iface, ipepLoc, ipepRem, inQ, outQ, false); // see if it failed if (conn.Sock == null) { MessageBox.Show("failed to connect to " + ipepRem + ":" + conn.ErrorSrc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); conn.Close(); return; } // check to see if already listed if (iface.htConns[conn] != null) { MessageBox.Show("Already connected to " + ipepRem, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); conn.Close(); return; } // add connection to interface // note stupid syntax; brain dead Collection class only sorts Dict objects... iface.htConns[conn] = conn; _connect.Dispose(); MEETInDespatch indesp = new MEETInDespatch("udp" + conn.IpepRemote, iface, inQ); indesp.Start(); conn.StartBidirectional(); m_log.Add("\tdone."); }
private void bConnect_Click(object sender, System.EventArgs e) { IPHostEntry iphe; IPAddress locIpaddr; m_log.Add("Checking local address..."); if (lbLocalIP.Text.Length == 0) { MessageBox.Show("Local IP address required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } try { iphe = Dns.Resolve(lbLocalIP.Text); } catch (Exception ex) { MessageBox.Show("Invalid Local IP Address: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } locIpaddr = iphe.AddressList[0]; m_log.Add("\tdone."); m_log.Add("Checking local port..."); if (tbPort.Text.Length == 0) { MessageBox.Show("Local UDP Port Required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } try { m_LocalPort = UInt16.Parse(tbPort.Text); } catch (Exception ex) { MessageBox.Show("0 < local port < 65536: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } m_mipLocalEndPoint = new MEETIPEndPoint(locIpaddr, m_LocalPort); m_log.Add("\tdone."); IPAddress remIpaddr; m_log.Add("Checking remote address..."); if (cbRemoteIP.Text.Length == 0) { MessageBox.Show("Remote IP address required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } try { iphe = Dns.Resolve(cbRemoteIP.Text); } catch (Exception ex) { MessageBox.Show("Invalid Remote IP Address: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } remIpaddr = iphe.AddressList[0]; m_log.Add("\tdone."); m_log.Add("Checking remote port..."); if (tbRemotePort.Text.Length == 0) { MessageBox.Show("UDP Remote Port Required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } try { m_RemotePort = UInt16.Parse(tbRemotePort.Text); } catch (Exception ex) { MessageBox.Show("0 < remote port < 65536: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } m_mipRemoteEndPoint = new MEETIPEndPoint(remIpaddr, m_RemotePort); m_log.Add("\tdone."); }