예제 #1
0
        public void Leave()
        {
            // Check if we can leave.
            /////////////////////////
            if (connection == null)
            {
                throw new SpreadException("No group to leave.");
            }

            // Get a new message.
            /////////////////////
            SpreadMessage leaveMessage = new SpreadMessage();

            // Set the group we're sending to.
            //////////////////////////////////
            leaveMessage.AddGroup(name);

            // Set the service type.
            ////////////////////////
            leaveMessage.ServiceType = SpreadMessage.LEAVE_MESS;

            // Send the message.
            ////////////////////
            connection.Multicast(leaveMessage);

            // No longer connected.
            ///////////////////////
            connection = null;
        }
예제 #2
0
        public void Join(SpreadConnection c, string groupName)
        {
            // Check if this group has already been joined.
            ///////////////////////////////////////////////
            if (this.connection != null)
            {
                throw new SpreadException("Already joined.");
            }

            // Set member variables.
            ////////////////////////
            this.connection = c;
            this.name = groupName;

            // Error check the name.
            ////////////////////////
            byte[] bytes;
            try
            {
                bytes = System.Text.Encoding.ASCII.GetBytes(name);
            }
            catch (Exception e)
            {
                throw new SpreadException("Encoding not supported: " + e);
            }
            for (int i = 0; i < bytes.Length; i++)
            {
                // Make sure the byte (character) is within the valid range.
                ////////////////////////////////////////////////////////////
                if ((bytes[i] < 36) || (bytes[i] > 126))
                {
                    throw new SpreadException("Illegal character in group name.");
                }
            }

            // Get a new message.
            /////////////////////
            SpreadMessage joinMessage = new SpreadMessage();

            // Set the group we're sending to.
            //////////////////////////////////
            joinMessage.AddGroup(name);

            // Set the service type.
            ////////////////////////
            joinMessage.ServiceType = SpreadMessage.JOIN_MESS;

            // Send the message.
            ////////////////////
            connection.Multicast(joinMessage);
        }
예제 #3
0
        // Constructor.
        ///////////////
        internal MembershipInfo(SpreadConnection connection, SpreadMessage message, bool daemonEndianMismatch)
        {
            // Set local variables.
            ///////////////////////
            this.serviceType = message.ServiceType;
            this.group = message.Sender;
            this.members = message.Groups;

            // Is this a regular membership message.
            ////////////////////////////////////////
            if (IsRegularMembership)
            {
                // Extract the groupID.
                ///////////////////////
                int dataIndex = 0;
                int[] id = new int[3];
                id[0] = SpreadConnection.toInt(message.Data, dataIndex);
                dataIndex += 4;
                id[1] = SpreadConnection.toInt(message.Data, dataIndex);
                dataIndex += 4;
                id[2] = SpreadConnection.toInt(message.Data, dataIndex);
                dataIndex += 4;
                // Endian-flip?
                ///////////////
                if (daemonEndianMismatch)
                {
                    id[0] = SpreadConnection.flip(id[0]);
                    id[1] = SpreadConnection.flip(id[1]);
                    id[2] = SpreadConnection.flip(id[2]);
                }

                // Create the group ID.
                ///////////////////////
                this.groupID = new GroupID(id[0], id[1], id[2]);

                // Get the number of groups.
                ////////////////////////////
                int numGroups = SpreadConnection.toInt(message.Data, dataIndex);
                if (daemonEndianMismatch)
                {
                    numGroups = SpreadConnection.flip(numGroups);
                }
                dataIndex += 4;

                // Get the groups.
                //////////////////
                this.groups = new SpreadGroup[numGroups];
                for (int i = 0; i < numGroups; i++)
                {
                    this.groups[i] = connection.toGroup(message.Data, dataIndex);
                    dataIndex += SpreadConnection.MAX_GROUP_NAME;
                }
            }
        }
예제 #4
0
 // Package constructor.
 ///////////////////////
 internal SpreadGroup(SpreadConnection connection, String name)
 {
     // Store member variables.
     //////////////////////////
     this.connection = connection;
     this.name = name;
 }
예제 #5
0
        public SpreadGroup()
        {
            // There is no connection yet.
            //////////////////////////////
            connection = null;

            // There is no name.
            ////////////////////
            name = null;
        }
예제 #6
0
파일: Form1.cs 프로젝트: pepipe/ISEL
        private void button1_Click(object sender, EventArgs e)
        {
            string address = null;
            int port = 0;
            string user = textBox1.Text;
            handler = new SpreadConnection.MessageHandler(messageReceived);
            try
            {
                connection = new SpreadConnection();
                connection.Connect(address, port, user, false, true);
                rtt = new Thread(new ThreadStart(this.run));
                rtt.Start();
            }
            catch (SpreadException ex)
            {
                MessageBox.Show("There was an error connecting to the daemon."+ex.Message);

            }
            catch (Exception ex)
            {
                MessageBox.Show("Can't find the daemon " + address+ex.Message);

            }
        }