Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wspy-multiplex
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-multiplex
Commits
e23ed990
Commit
e23ed990
authored
Aug 22, 2013
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added basic files
parent
8137fe50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
0 deletions
+106
-0
__init__.py
__init__.py
+1
-0
connection.py
connection.py
+105
-0
No files found.
__init__.py
0 → 100644
View file @
e23ed990
from
connection
import
MuxConnection
,
Channel
connection.py
0 → 100644
View file @
e23ed990
import
socket
from
threading
import
Thread
from
twspy
import
Connection
class
Multiplexer
(
object
):
def
__init__
(
self
,
sock
):
self
.
channels
=
[]
self
.
number
=
0
self
.
conn
=
MuxConnection
(
sock
)
def
__str__
(
self
):
return
'<Multiplexer #channels=%d at %s>'
\
%
(
len
(
self
.
channels
),
self
.
address_str
())
def
address_str
(
self
):
try
:
return
'%s:%d'
%
self
.
conn
.
sock
.
getpeername
()
except
socket
.
error
:
return
'closed connection'
def
add_channel
(
self
,
channel
):
self
.
channels
.
append
(
channel
)
self
.
number
+=
1
return
self
.
number
def
send
(
self
,
message
,
channel
):
raise
NotImplementedError
def
recv
(
self
,
channel
):
raise
NotImplementedError
def
send_forever
(
self
):
raise
NotImplementedError
def
receive_forever
(
self
):
raise
NotImplementedError
def
run
(
self
):
sender
=
Thread
(
self
.
send_forever
)
sender
.
daemon
=
True
sender
.
start
()
receiver
=
Thread
(
self
.
receive_forever
)
receiver
.
daemon
=
True
receiver
.
start
()
def
MuxConnection
(
Connection
):
pass
class
Channel
(
object
):
def
__init__
(
self
,
mux
):
self
.
mux
=
mux
self
.
number
=
mux
.
add_channel
(
self
)
def
__str__
(
self
):
return
'<Channel #%d at %s>'
%
(
self
.
number
,
self
.
mux
.
address_str
())
def
send
(
self
,
message
):
self
.
mux
.
send
(
message
,
self
)
def
recv
(
self
):
return
self
.
mux
.
recv
(
self
)
def
onopen
(
self
):
return
NotImplemented
def
onmessage
(
self
,
message
):
return
NotImplemented
def
onclose
(
self
,
code
=
None
,
reason
=
''
):
return
NotImplemented
if
__name__
==
'__main__'
:
from
twspy
import
websocket
class
EchoChannel
(
Channel
):
def
__init__
(
self
,
mux
,
name
):
Channel
.
__init__
(
self
,
mux
)
self
.
name
=
name
def
onopen
(
self
):
print
self
.
name
+
': opened on %s:%d'
%
self
.
sock
.
getpeername
()
def
onmessage
(
self
,
message
):
print
self
.
name
+
': message:'
,
message
self
.
send
(
message
)
def
onclose
(
self
,
msg
):
print
self
.
name
+
': closed'
server
=
websocket
()
server
.
bind
((
''
,
8000
))
server
.
listen
()
while
True
:
client
,
address
=
server
.
accept
()
mux
=
Multiplexer
(
client
)
a
=
EchoChannel
(
mux
,
'A'
)
b
=
EchoChannel
(
mux
,
'B'
)
mux
.
run
()
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