Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
telemersion
Telemersive Switchboard
Commits
6d1b0a91
Commit
6d1b0a91
authored
Feb 19, 2021
by
Roman Haefeli
Browse files
One2OneBi: add logger and catch all
parent
a6997adc
Changes
1
Hide whitespace changes
Inline
Side-by-side
proxies/udp_one2onebi.py
View file @
6d1b0a91
...
...
@@ -9,6 +9,7 @@ import socket
import
sys
import
threading
import
time
import
logging
class
One2OneBiProxy
(
threading
.
Thread
):
"""
...
...
@@ -17,7 +18,7 @@ class One2OneBiProxy(threading.Thread):
through a server with a public IP running this script.
"""
def
__init__
(
self
,
listen_port
=
None
,
listen_address
=
'0.0.0.0'
):
def
__init__
(
self
,
listen_port
=
None
,
listen_address
=
'0.0.0.0'
,
logger
=
None
):
super
(
One2OneBiProxy
,
self
).
__init__
()
if
not
isinstance
(
listen_port
,
int
)
or
not
1024
<=
listen_port
<=
65535
:
raise
ValueError
(
'Specified port "%s" is invalid.'
%
listen_port
)
...
...
@@ -28,36 +29,42 @@ class One2OneBiProxy(threading.Thread):
except
socket
.
error
as
msg
:
raise
self
.
kill_signal
=
False
self
.
logger
=
logger
def
run
(
self
):
client1
=
None
client2
=
None
while
not
self
.
kill_signal
:
try
:
data
,
addr
=
self
.
sock
.
recvfrom
(
65536
)
except
socket
.
timeout
:
continue
try
:
data
,
addr
=
self
.
sock
.
recvfrom
(
65536
)
except
socket
.
timeout
:
continue
# Assigning clients
if
addr
!=
client1
and
addr
!=
client2
:
client1
=
client2
client2
=
addr
# Assigning clients
if
addr
!=
client1
and
addr
!=
client2
:
client1
=
client2
client2
=
addr
# transmit data
if
client1
and
client2
:
if
addr
==
client1
:
self
.
sock
.
sendto
(
data
,
client2
)
elif
addr
==
client2
:
self
.
sock
.
sendto
(
data
,
client1
)
# transmit data
if
client1
and
client2
:
if
addr
==
client1
:
self
.
sock
.
sendto
(
data
,
client2
)
elif
addr
==
client2
:
self
.
sock
.
sendto
(
data
,
client1
)
except
:
self
.
logger
.
exception
(
'Oops, something went wrong!'
,
extra
=
{
'stack'
:
True
})
def
stop
(
self
):
self
.
kill_signal
=
True
self
.
join
()
def
main
():
logger
=
logging
.
getLogger
()
handler
=
logging
.
StreamHandler
(
sys
.
stderr
)
logger
.
addHandler
(
handler
)
try
:
proxy
=
One2OneBiProxy
(
listen_port
=
int
(
sys
.
argv
[
1
]))
proxy
=
One2OneBiProxy
(
listen_port
=
int
(
sys
.
argv
[
1
])
,
logger
=
logger
)
proxy
.
start
()
proxy
.
join
()
except
KeyboardInterrupt
:
...
...
Write
Preview
Supports
Markdown
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