problems with the messageSender method

HI, my name is rotimi, and i am taking my masters in distributed Systems and networks, and one of the major courses im taking is java. The course has been rather non-trivial for me since i started, but i hav been coping..Unfortunately i have gotten stuck in one of the programs i am writing and id like to get some help. The description is below and as follows:

This class below implements the sender side of the data link layer. I have been able to write the class to a full extent. the only problem is the sendMessage method.
At the moment it just passes the whole message directly to the physical layer. That is, of course, wrong! the sendMessage method needs to split large messages into several smaller segments and encode each segment as a frame in the required
format before passing it to sendFrame.
This is the problem i have..i havent been able to work out this method.

The Frame which the messages have to be passed through has a format:
Example ( Hello : 500 : . )
where "(" is a frame delimeter(start), "Hello"(message segment), ":"is a field delimeter, "500" is the check sum, ":"is a field delimeter, "." is an End of message flag, and "(" is a Frame delimeter(end). This is for short messages.

For Longer messages
Suppose the following message is to be sent:

Term pattern 12:12:6

Suppose also that the physical layer MTU is 18. The message would need to be split into three separate frames, like this:

(Term patte:982:+)
(rn 12::12:512:+)
(::6:112:.)

The first two frames end with "+)" rather than ".)" because each is followed by another frame.
The message segments are less than 18 characters long.
This is because the MTU value applies to the whole frame.
Each ':' in 12:12:6 is expanded to "::" to distinguish it from a field delimiter.
However, only the original single ':'s count towards the checksums.
The second frame is only 17 characters long.
There isn't room for the expanded second ':' in this frame.
The final frame is shorter than the others.
The final remaining message segment doesn't require a frame of the maximum allowed length








public class MessageSender
{
// Attributes --------------------------------------------------------

private FrameSender physicalLayer; // physical layer object
private boolean quiet; // true=quiet mode (suppress prompts and status info)

/**
* MessageSender constructor
* @param physicalLayer physical layer object with frame sender service
* (this already has been created and initialized by a TestSender class(for the * Application which i did not put here)
* @param quiet true for quiet mode which suppresses prompts and status info
*/

public MessageSender(FrameSender physicalLayer, boolean quiet)
{
// Initialize attributes and report status

this.physicalLayer = physicalLayer;
this.quiet = quiet;
if (!quiet) System.out.println("Data link layer ready");
}

// -------------------------------------------------------------------

/**
* Send a message
* @param message the message to be sent (may be any length)
* @throws ProtocolException in the event of failure
*/

public void sendMessage(String message) throws ProtocolException
{
// Announce action
// This is to help with debugging, although it's not required by the protocol

if (!quiet)
System.out.println("Sending message => " + message);

// The following statement shows how the frame sender is invoked.
// At the moment it just passes the whole message directly to the
// physical layer. That is, of course, wrong!

physicalLayer.sendFrame(message);

// sendMessage needs to split large messages into several smaller
// segments and encode each segment as a frame in the required
// format before passing it to sendFrame. See the coursework
// specification and other class documentation for further info.
//this is the part that i need help in.

} // end of method sendMessage


} // end of class MessageSender
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories