コード例 #1
0
ファイル: User.cs プロジェクト: pepipe/ISEL
    public User(String user, String address, int port)
    {
        handler = new SpreadConnection.MessageHandler( messageReceived );

        // Establish the spread connection.
        ///////////////////////////////////
        try {
            connection = new SpreadConnection();
            connection.Connect(address, port, user, false, true);
        }
        catch(SpreadException e) {
            Console.Error.WriteLine("There was an error connecting to the daemon.");
            Console.WriteLine(e);
            Environment.Exit(1);
        }
        catch(Exception e) {
            Console.Error.WriteLine("Can't find the daemon " + address);
            Console.WriteLine(e);
            Environment.Exit(1);
        }

        rt = new recThread( connection );
        Thread rtt = new Thread(new ThreadStart(rt.run));
        rtt.Start();
        // Show the menu.
        /////////////////
        PrintMenu();

        // Get a user command.
        //////////////////////
        while(true) {
            UserCommand();
        }
    }
コード例 #2
0
ファイル: Spread.cs プロジェクト: jonas12/SD-LI61D-1112
        // 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;
                }
            }
        }
コード例 #3
0
ファイル: Spread.cs プロジェクト: jonas12/SD-LI61D-1112
        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;
        }
コード例 #4
0
ファイル: Spread.cs プロジェクト: jonas12/SD-LI61D-1112
        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);
        }
コード例 #5
0
ファイル: Spread.cs プロジェクト: jonas12/SD-LI61D-1112
 // Package constructor.
 ///////////////////////
 internal SpreadGroup(SpreadConnection connection, String name)
 {
     // Store member variables.
     //////////////////////////
     this.connection = connection;
     this.name = name;
 }
コード例 #6
0
ファイル: Spread.cs プロジェクト: jonas12/SD-LI61D-1112
        public SpreadGroup()
        {
            // There is no connection yet.
            //////////////////////////////
            connection = null;

            // There is no name.
            ////////////////////
            name = null;
        }
コード例 #7
0
ファイル: recThread.cs プロジェクト: pepipe/ISEL
 public recThread(SpreadConnection aConn)
 {
     connection=aConn;
 }
コード例 #8
0
ファイル: Flooder.cs プロジェクト: nuxleus/Nuxleus.Extf
	public Flooder(String user, int numMessages, int numBytes, String address, int port, bool readOnly, bool writeOnly) {
		try {
			// Start timer.
			///////////////
			DateTime startTime = DateTime.Now;
			
			// Connect.
			///////////
			SpreadConnection connection = new SpreadConnection();
			connection.Connect(address, port, user, false, false);
			string privateName = connection.PrivateGroup.ToString();
			
			// Join.
			////////
			SpreadGroup group = new SpreadGroup();
			if(readOnly) {
				Console.WriteLine("Only receiving messages");
				group.Join(connection, "flooder");
			}
			else if(writeOnly) {
				Console.WriteLine("Starting multicast of " + numMessages + " messages, " + numBytes + " bytes each (self discarding).");
			}
			else {
				group.Join(connection, "flooder");
				Console.WriteLine("Starting multicast of " + numMessages + " messages, " + numBytes + " bytes each.");
			}
			
			// The outgoing message.
			////////////////////////
			SpreadMessage mout = null;
			if(readOnly == false) {
				mout = new SpreadMessage();
				mout.IsSafe = true;
				mout.Data = new byte[numBytes];
				mout.AddGroup("flooder");
			}
			
			// Send/Receive.
			////////////////
			for(int i = 1 ; i <= numMessages ; i++) {
				// Send.
				////////
				if(readOnly == false) {
					connection.Multicast(mout);
					}
				
				// Receive.
				///////////
				if((readOnly) || ((i > 50) && (writeOnly == false))) {
					SpreadMessage min;
					do {
						min = connection.Receive();
					}
					while((readOnly == false) && (privateName.Equals(min.Sender.ToString()) == false));
				}
				
				// Report.
				//////////
				if((i % 1000) == 0) {
					Console.WriteLine("Completed " + i + " messages");
				}
			}
			
			// Stop timer.
			//////////////
			DateTime stopTime = DateTime.Now;
			TimeSpan time = stopTime.Subtract(startTime);
			double Mbps = numBytes;
			Mbps *= numMessages;
			Mbps *= 8;
			if((readOnly == false) && (writeOnly == false))
				Mbps *= 2;
			Mbps *= 1000;
			Mbps /= time.TotalMilliseconds;
			Mbps /= (1024 * 1024);
			Console.WriteLine("Time: " + time + "ms (" + (int)Mbps + "." + (((int)(Mbps * 100)) % 100) + " Mbps)");
		}
		catch(Exception e) {
			Console.WriteLine(e);
		}
	}