Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
D
distributed-calculator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tammam.alsoleman
distributed-calculator
Commits
6bfb7ac4
Commit
6bfb7ac4
authored
Nov 12, 2025
by
tammam.alsoleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Last update
parent
484f833c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
13 deletions
+2
-13
client_gateway.py
client-gateway/client_gateway.py
+1
-2
server.js
multiplication-service/server.js
+1
-11
No files found.
client-gateway/client_gateway.py
View file @
6bfb7ac4
import
sys
import
os
# إضافة مسار المجلد generated إلى Python path
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'generated'
))
...
...
@@ -102,7 +101,7 @@ def main():
client
.
get_history
()
elif
choice
==
"3"
:
print
(
"
👋
Goodbye!"
)
print
(
"Goodbye!"
)
break
else
:
...
...
multiplication-service/server.js
View file @
6bfb7ac4
...
...
@@ -3,7 +3,6 @@ const protoLoader = require('@grpc/proto-loader');
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
).
promises
;
// تحميل بروتوكول gRPC
const
PROTO_PATH
=
path
.
join
(
__dirname
,
'../proto/calculator.proto'
);
const
packageDefinition
=
protoLoader
.
loadSync
(
PROTO_PATH
,
{
keepCase
:
true
,
...
...
@@ -14,11 +13,10 @@ const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
});
const
calculatorProto
=
grpc
.
loadPackageDefinition
(
packageDefinition
).
calculator
;
// تخزين العمليات
let
operations
=
[];
class
MultiplicationService
{
// دالة الضرب
multiply
(
call
,
callback
)
{
const
{
a
,
b
}
=
call
.
request
;
const
result
=
a
*
b
;
...
...
@@ -32,10 +30,8 @@ class MultiplicationService {
timestamp
};
// حفظ العملية في الذاكرة
operations
.
push
(
operation
);
// حفظ في ملف السجل
this
.
logToFile
(
operation
);
console
.
log
(
` Multiplication operation:
${
a
}
×
${
b
}
=
${
result
}
`
);
...
...
@@ -46,7 +42,6 @@ class MultiplicationService {
});
}
// دالة جلب السجل (Streaming)
getOperationHistory
(
call
)
{
console
.
log
(
' Sending operation history...'
);
...
...
@@ -55,12 +50,10 @@ class MultiplicationService {
operations
:
operations
};
// إرسال السجل
call
.
write
(
history
);
call
.
end
();
}
// دالة حفظ في ملف
async
logToFile
(
operation
)
{
try
{
const
logEntry
=
`[
${
operation
.
timestamp
}
]
${
operation
.
type
}
:
${
operation
.
a
}
×
${
operation
.
b
}
=
${
operation
.
result
}
\n`
;
...
...
@@ -75,13 +68,11 @@ function main() {
const
server
=
new
grpc
.
Server
();
const
multiplicationService
=
new
MultiplicationService
();
// تسجيل الخدمة
server
.
addService
(
calculatorProto
.
Calculator
.
service
,
{
Multiply
:
multiplicationService
.
multiply
.
bind
(
multiplicationService
),
GetOperationHistory
:
multiplicationService
.
getOperationHistory
.
bind
(
multiplicationService
)
});
// بدء الخادم
server
.
bindAsync
(
'0.0.0.0:50053'
,
grpc
.
ServerCredentials
.
createInsecure
(),
...
...
@@ -97,7 +88,6 @@ function main() {
);
}
// معالجة إغلاق التطبيق بشكل أنيق
process
.
on
(
'SIGINT'
,
()
=>
{
console
.
log
(
'
\
n Shutting down Multiplication Service...'
);
process
.
exit
(
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment