Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Christopher Willcocks
Abstract
The finished Messenger application successfully achieves the following: Basic objective 1. Allows two users to communicate over a network using socket programming. 2. Users can send messages to each other. 3. Application manager user status (online and offline) is displayed. Intermediate objective 4. Supports multiple users tested 30 users successfully uses UDP Multicasting, see design section of this report for justification of technology. Advanced objective 5. Uses a GUI with menus, buttons, icons and hotkeys. 6. File transmission to individual user within chat. Files can be sent with sizes over the 101mb memory cap tested 400mb file successfully (6min, 20secs) and 10gb file on localhost (40seconds). Sends in a TCP stream over the same UDP port. Open and save dialogs on each end. File can be declined with appropriate handshake messages and responses. Specialized objective 7. Sending and receiving messages in HTML format for user name and the actual chat message independently. This allows for avatars in name using <img> tags, or images within the text. Other HTML tags such as bold, italics, tables and text size can be sent. Messages are appended within HTML body to be displayed incrementally. 8. Custom colour chooser supported on different operating systems. Can format name and message independently. 9. Viewing and saving chats to hard drive with dialogs supported on different operating systems. 10. Native platform look and feel and compatibility between platforms tested on Linux and Windows. 11. Ability to logout and rebind sockets without creating a new instance of the program. 12. Login manager to change login name and set a different port. 13. Only one port used, and two sockets one for sending and one for receiving. This includes file transfer as well as HTML messages. 14. Scrollbars and automated focus and caret positioning in colour choosing tags. Messages can also be sent using Shift + Enter keys. Enter alone sends a newline, converted to <br> html tag when sent.
Christopher Willcocks
Design
Technology used and justification
The application has the ability to broadcast messages to multiple recipients. To do this, each messenger opens two Multicast sockets one to send and one to receive. This way, there is no server needed technically each instance of the application is its own server. The Multicast sockets are bound to a user set port number. They then join a group based on the IPv4 Multicast range of 224.0.0.0 through 239.255.255.255. The default IP in the application is 230.0.0.1 this is a reserved IP. For example if eighty users want to chat to each other in one huge chat, they can set the IP address to 230.0.0.1 and the port to 5000 and all talk. But if Fred and Sam wish to have a private chat only with each other, they can set the IP address to 230.0.0.1 and the port to 5001. The following diagram shows how the application uses UDP Multicasting to broadcast to more than two users on port 5000, while at the same time Fred and Sam are having a private chat and sending a message simultaneously on port 5001:
Multicast IP: 230.0.0.1 PORT: 5000 Mark James PORT: 5001 Fred
Chris
Ryan
Ed
Laura
Sam
Key
Messenger application
Message broadcast
As you can see from the diagram, Chris is broadcasting a message to Mark, James, Ryan, Ed and Laura. Also note that Chris is broadcasting a message to himself. This is unavoidable as Chris is in the Multicast group and same bound port. But this is also a useful feature, as Chris will want to see the message that he has typed. At the same time, you can see what happens when messages are broadcast simultaneously. Fred & Sam both broadcast a message within the group and bound IP; they both receive their two messages. Saturday, 01 December 2007
Distributed Systems & Networks assignment I Seek You This approach has advantages and disadvantages:
Christopher Willcocks
Advantages: Allows broadcasting to a huge number of users. Does not require a separate server to be run outside of the messenger. Automatically receives users own message does not require a dummy message. This is useful for displaying the sent message in a receive chat window. Does not require two-way-communication (a point-to-point channel) for communication between users. Works fantastically for quick LAN chats. Only two sockets are required for each messenger instance. Does not require a user database. Everything can be managed internally. Disadvantages: Data is broadcast using UDP there is no guarantee that the message will be delivered packet loss may occur so in a worst case the chat message does not get received. An open port is required.
Christopher Willcocks
Messenger: Alex
Send file transfer request to client with name James (broadcast to all clients) while (true) { // Receive packets
Messenger: James
while (true) { // Receive packets
if (request = James) { Send response confirmation to Alex. } if (chunk = James) { Append chunk to an indexed buffer. } if (complete = James) { Save buffer to hard disk. }
if (confirmation = Alex){ Split file into chunks and send one at a time to James When all are sent, send a completion packet to James }
Why this approach is unsuitable: This approach has an initial handshake and assembles the UDP packets in the correct order when appended to a buffer. However it does not take into account packet loss the only way to do this would be to have a checksum or confirmation check on each datagram followed by resending of the datagram if it fails. It is overly complicated and I decided to try a different direction: Different direction TCP: To integrate TCP with the broadcasting system, I used the initial handshake as shown in the above diagram to establish a connection with only two peers from a large group. I then opened a TCP stream on the same Multicast bound port between the two peers. This is shown in the following diagram:
Multicast IP: 230.0.0.1 PORT: 5000 A B D E
Key
Messenger application
Message broadcast
TCP Stream
Receive socket
Christopher Willcocks
As you can see from the diagram; A is broadcasting a message to everyone within the group however the message does not get received by C or F as they locked in the file transfer. However C and F can broadcast messages to everyone in the group, whilst downloading, as this is done on a separate thread although they do not receive their own messages. To conclude, this approach has advantages and disadvantages: Advantages: Allows guaranteed reliable data transfer of any file size. Tested 10gb file locally and a 400mb file successfully across the network. Simple integration with UDP message broadcasting system. Does not require an additional port to be opened. Only one handshake required. Disadvantages: The two peers in the file transfer cannot receive normal messages from themselves or anyone else within the Multicast group.
Implementation
User guide
The application requires a machine with a java runtime environment installed. It requires a network with an unbound port. It is ready for distribution. Simply open the Messenger.jar file with the Java Platform SE Binary file to load a new instance of the application. You can talk locally by opening two (or multiple) instances of the application on the same port. You can talk across a LAN by opening instances of the application, on different machines within the network, on the same port. Click About > Help when in the application.
Christopher Willcocks
This diagram shows the exploded view for when a download is received. If, at any stage, the downloader wishes to cancel a message is displayed saying X declined the file transfer to the uploader.
Christopher Willcocks
Christopher Willcocks
References
Listed are references besides the Java API and lecture slides, used in creation of the report and application: [21 November, 19:04] Used for help understanding sockets and TCP file transfer tutorial: http://java.sun.com/docs/books/tutorial/networking/sockets/index.html [24 November, 20:35] Used for learning how to implement UDP Multicasting: http://java.sun.com/docs/books/tutorial/networking/datagrams/index.html