Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MessageDecoder. Java Program needed. Create an interface MessageDecoder that has

ID: 3560097 • Letter: M

Question

MessageDecoder. Java Program needed.

Create an interface MessageDecoder that has a single abstract method decode(cipherText), where cipherText is the message to be decoded. The method will return the decoded message. Modify the classes SubstitutionCipher and ShuffleCipher, as described in Programming Problem 2, above, so that they implement MessageDecoder as well as the interface MessageEncoder described above. Finally, write a program that allows a user to encode and decode messages entered on the keyboard

Explanation / Answer

Implement Encoder.Text<MessageB> similarly. Then, add the encoders parameter to the ServerEndpoint annotation as follows:

Now, you can send MessageA and MessageB objects as WebSocket messages using the sendObject method as follows:

As in this example, you can have more than one encoder for text messages and more than one encoder for binary messages. Like endpoints, encoder instances are associated with one and only one WebSocket connection and peer, so there is only one thread executing the code of an encoder instance at any given time.