Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This repository contains a small chat server implementation to be used for Recitation 15.

### Getting Started
------
------asdlkhjasd;lkja;sldkjad
##### Forking the Repository
In order to gain access to this repository, we would like you to **Fork** the repsoitory, and then clone your fork onto your local machine. More information about forking can be found [here](https://help.github.com/articles/fork-a-repo/).

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/edu/cmu/cs/cs214/rec15/gui/ClientPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ public void startChat(String username, String port, String ip) {
*/
@Override
public void messageReceived(String username, String message) {

// TODO: Make the server show the timestamp of the received message

String newText = String.format(" %s: %s%n", username, message);
this.chatArea.append(newText);
chatArea.setCaretPosition(chatArea.getDocument().getLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ public void run() {
}


// TODO: Notify all clients when a new client joins the chat server

/**
* Callback for when a message is received by the server. Notifies all
* clients about the new message received
Expand All @@ -179,6 +177,10 @@ public void run() {
* Message sent by the client
*/
private void onNewMessage(Socket from, Message msg) {
// TODO: Add the server timestamp to the message received. Note:
// Message#setServerTimestamp was created for you in the Message
// class.

// Synchronize because we are iterating through all clients in a
// thread
synchronized (clients) {
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/edu/cmu/cs/cs214/rec15/server/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public class Message implements Serializable {
private String content;
private Date timestamp;
private String sender;
private Date serverTimestamp;


// TODO: Make the message also include a timestamp for when the server
// received the message

/**
* Constructor to create a message
*
Expand Down Expand Up @@ -67,6 +65,26 @@ public Date getTimestamp() {
}


/**
*
* @return Time at which the server received this message
*/
public Date getServerTimestamp() {
return new Date(serverTimestamp.getTime());
}


/**
* Sets the server timestamp
*
* @param receivedAt
* Time at which the server received this message
*/
public void setServerTimestamp(Date receivedAt) {
this.serverTimestamp = new Date(receivedAt.getTime());
}


/**
* @return the sender
*/
Expand Down