Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
http-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
http-server
Commits
b1066299
Commit
b1066299
authored
Nov 01, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add echoserver.pyx and client.pyx demo
parent
8cc525ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
0 deletions
+86
-0
src/client.pyx
src/client.pyx
+39
-0
src/echoserver.pyx
src/echoserver.pyx
+40
-0
src/stdlib/_socket.pxd
src/stdlib/_socket.pxd
+7
-0
No files found.
src/client.pyx
0 → 100644
View file @
b1066299
from
stdlib.string
cimport
Str
from
stdlib.socket
cimport
getaddrinfo
,
socket
,
AF_UNSPEC
,
SOCK_STREAM
,
AI_PASSIVE
,
MSG_WAITALL
,
SHUT_WR
,
SHUT_RD
from
libc.stdio
cimport
puts
,
printf
def
main
():
cdef
const
char
*
arg
cdef
Str
recv
loop
=
True
while
loop
:
b
=
input
(
"Message to send:
\
n
"
).
encode
()
arg
=
b
with
nogil
:
a
=
getaddrinfo
(
NULL
,
Str
(
"3490"
),
AF_UNSPEC
,
SOCK_STREAM
,
0
,
AI_PASSIVE
)[
0
]
s
=
socket
(
a
.
family
,
a
.
socktype
,
a
.
protocol
)
s
.
connect
(
a
.
sockaddr
)
msg
=
Str
(
arg
)
s
.
sendall
(
msg
)
s
.
shutdown
(
SHUT_WR
)
recv
=
s
.
recvall
()
printf
(
'received: %s
\
n
\
n
'
,
Str
.
to_c_str
(
recv
))
s
.
close
()
if
msg
!=
recv
:
puts
(
'sent and received are different'
)
if
msg
==
Str
(
'quit'
):
loop
=
False
main
()
src/echoserver.pyx
0 → 100644
View file @
b1066299
from
stdlib.string
cimport
Str
from
stdlib.socket
cimport
getaddrinfo
,
socket
,
AF_UNSPEC
,
SOCK_STREAM
,
AI_PASSIVE
,
SHUT_RD
,
SHUT_WR
from
libc.stdio
cimport
puts
,
printf
def
main
():
cdef
Str
recv
with
nogil
:
a
=
getaddrinfo
(
NULL
,
Str
(
"3490"
),
AF_UNSPEC
,
SOCK_STREAM
,
0
,
AI_PASSIVE
)[
0
]
s
=
socket
(
a
.
family
,
a
.
socktype
,
a
.
protocol
)
s
.
bind
(
a
.
sockaddr
)
s
.
listen
(
5
)
loop
=
True
while
loop
:
s1
=
s
.
accept
()
recv
=
s1
.
recvall
()
printf
(
'received: %s
\
n
\
n
'
,
Str
.
to_c_str
(
recv
))
if
recv
==
Str
(
'quit'
):
loop
=
False
s1
.
shutdown
(
SHUT_RD
)
s1
.
sendall
(
recv
)
s1
.
shutdown
(
SHUT_WR
)
s1
.
close
()
s
.
close
()
main
()
src/stdlib/_socket.pxd
View file @
b1066299
...
...
@@ -105,6 +105,13 @@ cdef extern from "<netinet/in.h>" nogil:
enum
:
INET6_ADDRSTRLEN
unsigned
long
htonl
(
unsigned
long
hostlong
)
unsigned
short
htons
(
unsigned
short
hostshort
)
unsigned
long
ntohl
(
unsigned
long
netlong
)
unsigned
short
ntohs
(
unsigned
short
netshort
)
cdef
extern
from
"<arpa/inet.h>"
nogil
:
const
char
*
inet_ntop
(
int
af
,
const
void
*
src
,
char
*
dst
,
socklen_t
size
)
...
...
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