Skip to content

Commit 7ab1ab5

Browse files
committedAug 6, 2023
distibutedbanking
0 parents  commit 7ab1ab5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2277
-0
lines changed
 

‎Bank/Client.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import random
2+
import json
3+
import os
4+
import sys
5+
import time
6+
from networking.udpSocket import udp_socket
7+
8+
9+
# Define a list of stocks with their ticker symbols and initial prices
10+
stocks = [
11+
{"symbol": "VW", "price": 170.0},
12+
{"symbol": "KIA", "price": 3000.0},
13+
{"symbol": "AUDI", "price": 400.0},
14+
{"symbol": "BMW", "price": 5000.0},
15+
]
16+
17+
18+
SERVER_HOSTNAME = os.environ.get("SERVER_HOSTNAME", "127.0.0.1")
19+
SERVER_PORT = int(os.environ.get("SERVER_PORT", "6789"))
20+
21+
22+
23+
24+
while True:
25+
# Simulate the prices of the stocks
26+
for stock in stocks:
27+
# Generate a random percentage change between -1% and +1%
28+
percent_change = random.uniform(-0.01, 0.01)
29+
# Calculate the new price based on the percent change
30+
new_price = stock["price"] * (1 + percent_change)
31+
# Update the stocks's price
32+
stock["price"] = new_price
33+
34+
# Print the updated prices of the stocks
35+
print("Updated prices of stocks:")
36+
for stock in stocks:
37+
print(f"{stock['symbol']}: {stock['price']}")
38+
39+
message = json.dumps(stocks)
40+
41+
try:
42+
udp_client = udp_socket(SERVER_HOSTNAME, SERVER_PORT)
43+
start_time= time.time()
44+
response_server = udp_client.send(SERVER_HOSTNAME, SERVER_PORT, message, 4096)
45+
end_time= time.time()
46+
roundtriptime= end_time - start_time
47+
print("Response from the server => %s" % response_server)
48+
print("Round-trip time => %.2f ms" % (roundtriptime * 1000))
49+
except Exception as e: # catch execption for catching the error
50+
print(f"Error occurred while sending/receiving data: {e}")
51+
sys.exit(1)
52+
53+
#user_input = input("Do you want to quit? (y/n)")
54+
#if user_input == "y":
55+
#break
56+
#
57+
time.sleep(300)

‎Dockerfile.Server

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM python:3
2+
3+
WORKDIR /Server
4+
5+
COPY ./Server ./Server
6+
7+
COPY ./networking ./Server/networking
8+
9+
COPY stockportfolio.thrift ./Server/
10+
11+
RUN apt-get update && apt-get install -y iputils-ping
12+
13+
14+
15+
# Install Conda
16+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
17+
bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda && \
18+
rm Miniconda3-latest-Linux-x86_64.sh && \
19+
export PATH="/opt/conda/bin:$PATH" && \
20+
echo "export PATH=/opt/conda/bin:$PATH" >> ~/.bashrc
21+
22+
# Activate Conda environment
23+
ENV PATH="/opt/conda/bin:$PATH"
24+
25+
RUN conda install -c conda-forge thriftpy2
26+
27+
RUN pip install rpyc
28+
29+
RUN pip install kafka-python
30+
31+
#RUN pip install aiokafka==0.8.0
32+
RUN pip install aiokafka
33+
#RUN pip install aiomonitor
34+
35+
36+
#ENTRYPOINT [ "python", "-u", "Server/Server.py" ]
37+
ENTRYPOINT ["python", "-X", "dev", "-u", "Server/Server.py"]
38+
39+
#CMD ["tail", "-f", "/dev/null"]
40+
EXPOSE 6789/UDP
41+

0 commit comments

Comments
 (0)
Please sign in to comment.