Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
ds-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Schulz
ds-project
Commits
7b56a0a0
"src/cmd/web/main.go" did not exist on "e217429e994bca47367b71548e0b970d556b8765"
Commit
7b56a0a0
authored
Jan 24, 2024
by
Alexander Schulz
Browse files
Options
Downloads
Patches
Plain Diff
feedback when non existing group selected
parent
0d7bdd18
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
client.py
+33
-24
33 additions, 24 deletions
client.py
server.py
+9
-0
9 additions, 0 deletions
server.py
with
42 additions
and
24 deletions
client.py
+
33
−
24
View file @
7b56a0a0
...
...
@@ -14,10 +14,15 @@ class Client(multiprocessing.Process):
def
run
(
self
):
print
(
"
Client: Up and running
"
)
while
True
:
action
=
input
(
"
Client: Enter type of action (
'
r
'
to register):
"
)
if
(
action
==
"
r
"
):
group
=
input
(
"
Client: Which group dou you want to join?
"
)
self
.
register
(
"
register
"
,
group
)
success
=
self
.
register
(
"
register
"
,
group
)
if
success
==
0
:
continue
send_thread
=
threading
.
Thread
(
target
=
self
.
send_message
)
receive_thread
=
threading
.
Thread
(
target
=
self
.
receive_messages
)
...
...
@@ -31,9 +36,6 @@ class Client(multiprocessing.Process):
send_thread
.
join
()
receive_thread
.
join
()
else
:
message
=
input
(
"
Client: Enter message:
"
)
print
(
message
)
def
register
(
self
,
message_type
,
message_group
):
PORT
=
49153
...
...
@@ -49,6 +51,9 @@ class Client(multiprocessing.Process):
print
(
'
Client: Received message from server:
'
,
data
.
decode
(
'
utf-8
'
))
if
data
.
decode
(
'
utf-8
'
)
==
"
Group does not exist
"
:
success
=
0
else
:
# search for server ip_address in message from server
ip_pattern
=
r
'
\b(?:\d{1,3}\.){3}\d{1,3}\b
'
matches
=
re
.
findall
(
ip_pattern
,
data
.
decode
(
'
utf-8
'
))
...
...
@@ -59,8 +64,12 @@ class Client(multiprocessing.Process):
#self.registered_server = server
print
(
"
Client: My server:
"
,
self
.
registered_server_address
)
success
=
1
broadcast_socket
.
close
()
return
success
def
send_message
(
self
):
PORT
=
50001
...
...
...
...
This diff is collapsed.
Click to expand it.
server.py
+
9
−
0
View file @
7b56a0a0
...
...
@@ -456,6 +456,7 @@ class Server(multiprocessing.Process):
if
group
not
in
self
.
local_group_cache
:
print
(
self
.
server_id
+
"
:
"
+
"
Group
"
+
group
+
"
doesn
'
t exist.
"
)
self
.
send_negative_reply_to_client
(
client_addr
)
else
:
print
(
self
.
server_id
+
"
:
"
+
"
Group
"
+
group
+
"
exists
"
)
...
...
@@ -482,6 +483,14 @@ class Server(multiprocessing.Process):
return
addr
def
send_negative_reply_to_client
(
self
,
client_addr
):
PORT
=
1001
message
=
"
Group does not exist
"
server_socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
server_socket
.
connect
((
self
.
server_address
,
PORT
))
server_socket
.
sendto
(
str
.
encode
(
message
),
client_addr
)
server_socket
.
close
()
def
send_reply_to_client
(
self
,
server_addr
,
client_addr
):
PORT
=
1000
message
=
'
Hi
'
+
client_addr
[
0
]
+
'
this is your groupchat server:
'
+
server_addr
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment