FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
f-stack/example/echo_server.py at dev · F-Stack/f-stack · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
F-Stack
/
f-stack
Public
Notifications
You must be signed in to change notification settings
Fork
962
Star
4.3k
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
f-stack
/
example
/
echo_server.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (36 loc) · 1.25 KB
Breadcrumbs
f-stack
/
example
/
echo_server.py
Copy path
File metadata and controls
41 lines (36 loc) · 1.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
# TCP echo server: send 1M timestamp messages to connected client.
# Based on issue #842 reproduction scenario.
import
socket
import
time
import
sys
import
signal
PORT
=
12373
MSG_COUNT
=
int
(
1e6
)
def
main
():
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
sock
.
bind
((
'0.0.0.0'
,
PORT
))
sock
.
listen
(
5
)
print
(
f"[server] listening on 0.0.0.0:
{
PORT
}
, will send
{
MSG_COUNT
}
messages"
,
flush
=
True
)
while
True
:
conn
,
addr
=
sock
.
accept
()
print
(
f"[server] connection from
{
addr
}
"
,
flush
=
True
)
try
:
buf
=
conn
.
recv
(
1024
)
start
=
time
.
time
()
sent
=
0
for
i
in
range
(
MSG_COUNT
):
conn
.
send
((
str
(
time
.
time_ns
())
*
200
).
encode
(
'utf-8'
))
sent
+=
1
conn
.
close
()
elapsed
=
time
.
time
()
-
start
print
(
f"[server] sent
{
sent
}
messages in
{
elapsed
:.3f
}
s"
,
flush
=
True
)
except
(
BrokenPipeError
,
ConnectionResetError
,
OSError
)
as
e
:
print
(
f"[server] connection error after
{
sent
}
msgs:
{
e
}
"
,
flush
=
True
)
try
:
conn
.
close
()
except
:
pass
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL