private void mnuPublish_Click(object sender, System.EventArgs e) { String s = s_hostname + " says \"" + tbText.Text + "\" at " + DateTime.UtcNow; Byte [] buffer = new Byte[s.Length + 1]; int len = Encoding.UTF8.GetBytes(s.ToCharArray(), 0, s.Length, buffer, 0); MEETDataPacket msp = new MEETDataPacket(MType.Announce, buffer); // manual broadcast... foreach (DictionaryEntry ifEntry in m_node.IFaces) { MEETIFace iface = (MEETIFace)ifEntry.Value; foreach (DictionaryEntry connEntry in iface.htConns) { MEETSockConnection conn = (MEETSockConnection)connEntry.Key; m_log.Add("sending to " + conn.IpepRemote); conn.OutQ.Enqueue(msp); } } }
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."); }