You will need to program two components in this project. First, the server that keeps track of the webpages and sends the notification whenever a webpage is updated. Second, a client that can subscribe and unsubscribe to updates about a webpage, and receives the notifications when the webpage changes.
SUBSCRIBE. Arguments: client IP address, client port, webpage URL. The server adds this information to its database. The server returns a SUCCESS return value if the request was successful. Otherwise, the server returns FAIL.
UNSUBSCRIBE. Arguments: client IP address, client port, webpage URL. The server deletes this information from its database. The server returns a SUCCESS return value if the request was successful. Otherwise, the server returns FAIL.
The server periodically downloads all the webpages in this database and if it has changed since the last time it downloaded the webpage, it will send notification to all the clients subscribed for updates for that webpage. The notification is also sent using JSON. Your server may store the webpages in the filesystem or in the memory. If you decide to use the filesystem, please create a directory called cache and put all the downloaded files inside that directory.
NOTIFY. Arguments: webpage URL.
The server is launched by using this command:
p1-server port
The server will listen on the specified port.
client-configure subscribe/unsubscribe server-ipaddr server-port callback-ipaddr callback-port url
server-ipaddr and server-port tells the client how to connect to the server. callback-ipaddr and callback-port tells the server the machine and port on which a client will listen for updates regarding the URL. The client sends a SUBSCRIBE or UNSUBSCRIBE message to the server with the provided URL.
client-callback port listens on a port and whenever it receives a NOTIFY from the server displays which URL has changed.
If the client is no longer listening (due to crashes, etc.), the server should detect that within 30 seconds and flush that subscription.
We have standardized the messages between the client and the server across the projects so that we can mix and match client and server implementations from different project submissions. When we grade the project, we will also test if your server implementation can operate with another standard compliant implementation of the client and your client can work with another standard compliant implementation of the server.
The fields in the subscription and unsubscription message are:
Field | Description |
action | Specifies the action desired by the client. Valid values are subscribe and unsubscribe |
ip | The IP address of the client that is listening for updates from the server. |
port | The TCP port at which the client is listening for updates from the server. Use port greater than 10000 |
url | The URL the client wishes to monitor for updates. |
When the server receives the subscribe or unsubscribe message, the server returns a message with the following field:
Field | Description |
returnvalue | Tells the client if the request to subscribe was successful. Valid values are success and fail. |
The fields in the notify message are:
Field | Description |
action | Tells the client the monitored url is updated. The only valid value is notify. |
url | The URL for which the action should be taken by the client. |
If you are not certain if your message is a valid JSON, you can use the validator at this URL: http://jsonlint.com/. You can copy and paste your message and the script there will tell you if your message is a valid JSON. If your message is not a valid JSON, it will not be possible to inter-operate your client and server with the client and server written by other students -- their JSON parsing routine might raise a flag and terminate.
The argument n at the end of the URL (change=n) tells the page how frequently it should change. If you use 1 for n, the page will change every second. If you find this page convenient for testing simple cases, feel free to use it. You are not required to use this page as a test case and we expect your system to work with more complex pages.