- The socket library functions can be summarized as follows:
socket.socket(family=AF INET, type=SOCK STREAM, proto=0, fileno=None)
Creates a socket object, default parameters are correct for this homework.socket.bind(address)
Binds the socket to an address that is (IP, PORT) pair.socket.close()
Closes the socket and all its connectionssocket.listen([backlog])
Enable a server to accept connections. Listens to the number of connections specified by backlog.socket.connect(address)
Connect to a remote socket at the address, the address is (IP, PORT) pair.socket.accept()
Accepts an incoming connection. The return value is a pair (conn, address) where conn is a new socket object usable to send and receive data on the connection, and address is the address bound to the socket on the other end of the connection.socket.recv(bufsize[, flags])
Receives a specified number of bytes from the TCP buffer. Returns a byte object representing the received data.socket.send(bytes[, flags])
Sends a specified number of bytes through the socket. Returns the number of bytes sent.socket.sendall(bytes[, flags])
Similar to send but this method continues to send data from bytes until either all data has been sent or an error occurs.
- We will implement a simple system consisting of 3 nodes. Namely, Client, Proxy, and Server. Topology is very simple and can be seen in Figure 2.
- The Server will hold a list of 10 elements as described in Table 1. Each entry will consist of an index value ranging from 0 to 9 and data of a single integer. The Proxy should be consistent with the server, that is any update made to the Proxy’s table should also be made to Server’s table.
- The Proxy server will hold half of the table in its process as described in Table 2, think of it as a cached version of the Server’s table. The Client will only communicate with the proxy server, if an element that is not present in the Proxy’s table is required proxy server will communicate with the Server to get that element and add it to its table by overwriting the oldest table entry.
-
Nodes will exchange proxy messages between them using the format below.
OP=XXX;IND=Ind1,Ind2,..;DATA=Dat1,Dat2,...;
-
Notice that fields are separated with semicolons(;). OP field describes which operation to do on the table, for more detail check Table 3. IND field tells which of the indexes are required for the operation. The DATA field is for integer data either from the server for operations like ”ADD” or as an update value from the client. Not all messages require every field. You can choose to omit the unused fields for certain operations.
-
Response messages have the same form as request messages. For example response to the ”ADD” message will have ”ADD” as the operation code and contain the result in the ”DATA” field.
-
For the first case, I have filled the remote server data buffer with put command. You can see the cache content at the “Proxy_process.py File Terminal”.
-
Client_process.py File Terminal
- Proxy_process.py File Terminal
- Server_process.m File Terminal
I have filled buffer indexes from 0 to 4 with values 0 to 4.
-
Then, I have filled remaining buffer indexes from 5 to 9 with values 5 to 9. As you can see, cache content will bu updated. According to most used data is put to the top of the cache.
-
Client_process.py
- Proxy_process.py File Terminal
- Here is the remote server. It also updated. Such that new added datas will be added to here.,
- Now, I will only change index 0 data with a value 12. I will check that will it work or not.
- Since I added 12 to the index0, cache will put it to the upper most index because it was the most recently accessed element. Also, I changed index 1 content with a number 45. Top element of the cache is a 12 as first. After addition of 45, 45 becomes a top element of the cache.
- Here, remote server content. It is updated as I put new datas to server.
- I added datas at the index 0,1,2. Since they exist at the cache, they will not connect to server. Values will be directly taken from cache memory since data exist in the cache
- By using get method, obtain values from corresponding indexes. Index 1 value exist in the cache. Hence, only index 3 and 5 will taken from server. Index 1 taken from cache.
- Clear Operation