Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
async-web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ba3cd5e4
authored
Mar 07, 2023
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Client ID yang sama ditolak
1 parent
6c90ccc2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
5 deletions
async_web/server.py
async_web/server.py
View file @
ba3cd5e
...
...
@@ -91,8 +91,15 @@ def main(argv=sys.argv[1:]):
@app.route
(
'/ws'
,
protocol
=
'websocket'
)
async
def
main_websocket
(
scope
,
receive
,
send
):
def
log_info
(
msg
):
if
client_id
:
msg
=
f
'{ip} {mem_id} Client {client_id} {msg}'
else
:
msg
=
f
'{ip} {mem_id} {msg}'
log
.
info
(
msg
)
async
def
kirim
(
d
:
dict
):
log
.
info
(
f
'{ip} {mem_id}
Send {d}'
)
log
_info
(
f
'
Send {d}'
)
await
send
(
d
)
async
def
kirim_pesan
(
d
:
dict
):
...
...
@@ -111,14 +118,20 @@ def main(argv=sys.argv[1:]):
try
:
d
=
module
.
login
(
d
)
client_id
=
d
[
'client_id'
]
ws_data
[
client_id
]
=
[]
if
client_id
in
ws_data
:
d
=
dict
(
code
=
91
,
message
=
f
'Client {client_id} masih terhubung'
)
client_id
=
None
else
:
ws_data
[
client_id
]
=
[]
except
BaseError
as
e
:
d
=
dict
(
code
=
e
.
code
,
message
=
e
.
message
)
except
Exception
:
msg
=
exception_message
()
log
.
error
(
msg
)
d
=
dict
(
code
=
91
,
message
=
'Login gagal'
)
log
.
info
(
f
'{ip} {mem_id}
Encode JSON {d}'
)
log
_info
(
f
'
Encode JSON {d}'
)
await
kirim_pesan
(
d
)
return
client_id
...
...
@@ -133,13 +146,13 @@ def main(argv=sys.argv[1:]):
except
asyncio
.
TimeoutError
:
await
run_queue
()
continue
log
.
info
(
f
'{ip} {mem_id}
Receive {message}'
)
log
_info
(
f
'
Receive {message}'
)
if
message
[
'type'
]
==
'websocket.connect'
:
await
kirim
({
'type'
:
'websocket.accept'
})
elif
message
[
'type'
]
==
'websocket.receive'
:
text
=
message
.
get
(
'text'
)
d
=
json
.
loads
(
text
)
log
.
info
(
f
'{ip} {mem_id}
Decode JSON {d}'
)
log
_info
(
f
'
Decode JSON {d}'
)
if
first
:
first
=
False
client_id
=
await
login
(
d
)
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment