Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wspy
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
wspy
Commits
3c2e6a88
Commit
3c2e6a88
authored
Nov 07, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added 'websocket' class, which provides a socket-like interface to WebSocket
parent
0fa31ac2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
websocket.py
websocket.py
+62
-0
No files found.
websocket.py
View file @
3c2e6a88
import
re
import
struct
import
socket
from
hashlib
import
sha1
from
frame
import
ControlFrame
,
receive_fragments
,
receive_frame
,
\
...
...
@@ -223,3 +224,64 @@ class WebSocket(object):
Handle a raised exception.
"""
pass
class
websocket
(
WebSocket
):
"""
Alternative implementation of web socket, extending the regular socket
object.
"""
def
__init__
(
self
,
family
=
socket
.
AF_INET
,
proto
=
0
):
sock
=
socket
.
socket
(
family
,
socket
.
SOCK_STREAM
,
proto
)
WebSocket
.
__init__
(
self
,
sock
)
def
bind
(
self
,
address
):
self
.
sock
.
bind
(
address
)
def
listen
(
self
,
backlog
):
self
.
sock
.
listen
(
backlog
)
def
accept
(
self
):
client
,
address
=
socket
.
socket
.
accept
(
self
)
client
=
websocket
(
client
)
client
.
handshake
()
return
client
,
address
def
recv
(
self
):
"""
Receive a sinfle frame.
"""
return
receive_frame
(
self
.
sock
)
def
send
(
self
,
frame
):
"""
Send a single frame.
"""
self
.
send_frame
(
frame
)
def
sendall
(
self
,
frames
):
"""
Send a list of frames.
"""
for
frame
in
frames
:
self
.
send
(
frame
)
def
getpeername
(
self
):
return
self
.
sock
.
getpeername
()
def
getsockname
(
self
):
return
self
.
sock
.
getpeername
()
def
setsockopt
(
self
,
level
,
optname
,
value
):
self
.
sock
.
setsockopt
(
level
,
optname
,
value
)
def
getsockopt
(
self
,
level
,
optname
):
return
self
.
sock
.
getsockopt
(
level
,
optname
)
if
__name__
==
'__main__'
:
sock
=
websocket
()
sock
.
bind
((
''
,
80
))
sock
.
listen
()
client
=
sock
.
accept
()
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