Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
noVNC
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
noVNC
Commits
7d146027
Commit
7d146027
authored
May 12, 2011
by
Joel Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pull websockify 284ef3cc1a54
Including HyBi-07 support and refactor of send/recv.
parent
5210330a
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
387 additions
and
90 deletions
+387
-90
websocket.py
utils/websocket.py
+355
-45
websockify
utils/websockify
+32
-45
No files found.
utils/websocket.py
View file @
7d146027
This diff is collapsed.
Click to expand it.
utils/websockify
View file @
7d146027
...
...
@@ -133,7 +133,7 @@ Traffic Legend:
# will be run in a separate forked process for each connection.
#
def
new_client
(
self
,
client
):
def
new_client
(
self
):
"""
Called after a new WebSocket connection has been established.
"""
...
...
@@ -156,9 +156,9 @@ Traffic Legend:
if
self
.
verbose
and
not
self
.
daemon
:
print
self
.
traffic_legend
# Stat proxying
# Sta
r
t proxying
try
:
self
.
do_proxy
(
client
,
tsock
)
self
.
do_proxy
(
tsock
)
except
:
if
tsock
:
tsock
.
close
()
...
...
@@ -169,14 +169,14 @@ Traffic Legend:
self
.
rec
.
close
()
raise
def
do_proxy
(
self
,
client
,
target
):
def
do_proxy
(
self
,
target
):
"""
Proxy client WebSocket to normal target socket.
"""
cqueue
=
[]
c
partial
=
""
c
_pend
=
0
tqueue
=
[]
rlist
=
[
client
,
target
]
rlist
=
[
self
.
client
,
target
]
tstart
=
int
(
time
.
time
()
*
1000
)
while
True
:
...
...
@@ -184,7 +184,7 @@ Traffic Legend:
tdelta
=
int
(
time
.
time
()
*
1000
)
-
tstart
if
tqueue
:
wlist
.
append
(
target
)
if
cqueue
:
wlist
.
append
(
client
)
if
cqueue
or
c_pend
:
wlist
.
append
(
self
.
client
)
ins
,
outs
,
excepts
=
select
(
rlist
,
wlist
,
[],
1
)
if
excepts
:
raise
Exception
(
"Socket exception"
)
...
...
@@ -199,53 +199,40 @@ Traffic Legend:
tqueue
.
insert
(
0
,
dat
[
sent
:])
self
.
traffic
(
".>"
)
if
client
in
outs
:
# Send queued target data to the client
dat
=
cqueue
.
pop
(
0
)
sent
=
client
.
send
(
dat
)
if
sent
==
len
(
dat
):
self
.
traffic
(
"<"
)
if
self
.
rec
:
self
.
rec
.
write
(
"
%
s,
\n
"
%
repr
(
"{
%
s{"
%
tdelta
+
dat
[
1
:
-
1
]))
else
:
cqueue
.
insert
(
0
,
dat
[
sent
:])
self
.
traffic
(
"<."
)
if
target
in
ins
:
# Receive target data, encode it and queue for client
buf
=
target
.
recv
(
self
.
buffer_size
)
if
len
(
buf
)
==
0
:
raise
self
.
EClose
(
"Target closed"
)
cqueue
.
append
(
self
.
encode
(
buf
)
)
cqueue
.
append
(
buf
)
self
.
traffic
(
"{"
)
if
client
in
ins
:
if
self
.
client
in
outs
:
# Send queued target data to the client
c_pend
=
self
.
send_frames
(
cqueue
)
cqueue
=
[]
#if self.rec:
# self.rec.write("%s,\n" %
# repr("{%s{" % tdelta + dat[1:-1]))
if
self
.
client
in
ins
:
# Receive client data, decode it, and queue for target
buf
=
client
.
recv
(
self
.
buffer_size
)
if
len
(
buf
)
==
0
:
raise
self
.
EClose
(
"Client closed"
)
if
buf
==
'
\xff\x00
'
:
raise
self
.
EClose
(
"Client sent orderly close frame"
)
elif
buf
[
-
1
]
==
'
\xff
'
:
if
buf
.
count
(
'
\xff
'
)
>
1
:
self
.
traffic
(
str
(
buf
.
count
(
'
\xff
'
)))
self
.
traffic
(
"}"
)
if
self
.
rec
:
self
.
rec
.
write
(
"
%
s,
\n
"
%
(
repr
(
"}
%
s}"
%
tdelta
+
buf
[
1
:
-
1
])))
if
cpartial
:
# Prepend saved partial and decode frame(s)
tqueue
.
extend
(
self
.
decode
(
cpartial
+
buf
))
cpartial
=
""
else
:
# decode frame(s)
tqueue
.
extend
(
self
.
decode
(
buf
))
else
:
# Save off partial WebSockets frame
self
.
traffic
(
".}"
)
cpartial
=
cpartial
+
buf
bufs
,
closed
=
self
.
recv_frames
()
tqueue
.
extend
(
bufs
)
#if self.rec:
# for b in bufs:
# self.rec.write(
# repr("}%s}%s" % (tdelta, b)) + ",\n")
if
closed
:
# TODO: What about blocking on client socket?
self
.
send_close
()
raise
self
.
EClose
(
closed
)
if
__name__
==
'__main__'
:
usage
=
"
\n
%
prog [options]"
...
...
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