Coder Social home page Coder Social logo

htmos6 / socket-proxy-server Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 21 KB

This project implements a simple system with three nodes: Client, Proxy, and Server. The Server holds a list of 10 elements, and the Proxy maintains a cached version of the Server's table. The Client communicates with the Proxy, which interacts with the Server when necessary. Nodes exchange messages using a specific format.

Python 88.59% MATLAB 11.41%
python3 matlab client-server proxy-server

socket-proxy-server's Introduction

Socket-Proxy-Server

1- How to Use Sockets ?

  • You can see the state diagram of TCP sockets in Figure 1. image
  • The socket library functions can be summarized as follows:
  1. socket.socket(family=AF INET, type=SOCK STREAM, proto=0, fileno=None)
    Creates a socket object, default parameters are correct for this homework.
  2. socket.bind(address)
    Binds the socket to an address that is (IP, PORT) pair.
  3. socket.close()
    Closes the socket and all its connections
  4. socket.listen([backlog])
    Enable a server to accept connections. Listens to the number of connections specified by backlog.
  5. socket.connect(address)
    Connect to a remote socket at the address, the address is (IP, PORT) pair.
  6. 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.
  7. socket.recv(bufsize[, flags])
    Receives a specified number of bytes from the TCP buffer. Returns a byte object representing the received data.
  8. socket.send(bytes[, flags])
    Sends a specified number of bytes through the socket. Returns the number of bytes sent.
  9. 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.

2- Simple Proxy Server

  • 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.

image

2.1- Operation Specifications

  • 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.

image

  • 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.

image

  • 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.

image

3- Test Results

  • 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

image

  • Proxy_process.py File Terminal

image

  • Server_process.m File Terminal
    I have filled buffer indexes from 0 to 4 with values 0 to 4.

image

  • 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

image

  • Proxy_process.py File Terminal

image

  • Here is the remote server. It also updated. Such that new added datas will be added to here.,

image

  • Now, I will only change index 0 data with a value 12. I will check that will it work or not.

image

  • 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.

image

  • Here, remote server content. It is updated as I put new datas to server.

image

  • 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

image

image

  • 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.

image

image

image

  • Clear Operation

image

image

image

socket-proxy-server's People

Contributors

htmos6 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.