-
Notifications
You must be signed in to change notification settings - Fork 11
added logging to ddp messages #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hmn
wants to merge
10
commits into
hthiery:master
Choose a base branch
from
hmn:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3a3e72d
added logging to ddp messages
c7f0edb
Merge branch 'master' of https://github.com/hthiery/python-ps4
01e804d
trying to fix dependencies
43a2c1e
Merge branch 'master' of https://github.com/hthiery/python-ps4
4cdfad1
handle errors in broadcast better
c961db2
added docker testing/dev env
004bdc1
Merge branch 'master' of github.com:hmn/python-ps4; branch 'master' o…
5d02bd4
return first item only
d7a7f46
handle missing data from search
d808778
use dict instead of list
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,15 @@ | |
|
|
||
| import re | ||
| import socket | ||
| import logging | ||
|
|
||
| UDP_IP = '0.0.0.0' | ||
| UDP_IP = '' | ||
| UDP_PORT = 0 | ||
|
|
||
| DDP_PORT = 987 | ||
| DDP_VERSION = '00020020' | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| def get_ddp_message(msg_type, data=None): | ||
| """Get DDP message.""" | ||
|
|
@@ -66,18 +68,36 @@ def get_ddp_launch_message(credential): | |
|
|
||
| def _send_recv_msg(host, broadcast, msg, receive=True): | ||
| """Send a ddp message and receive the response.""" | ||
| sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
| sock.bind((UDP_IP, UDP_PORT)) | ||
| sock.settimeout(3.0) | ||
|
|
||
| if broadcast: | ||
| sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | ||
| host = '255.255.255.255' | ||
|
|
||
| sock.sendto(msg.encode('utf-8'), (host, DDP_PORT)) | ||
|
|
||
| if receive: | ||
| return sock.recvfrom(1024) | ||
| try: | ||
| sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
| except OSError as error: | ||
| _LOGGER.error('failed to create socket, %s', error) | ||
| return | ||
| try: | ||
| sock.bind((UDP_IP, UDP_PORT)) | ||
| sock.settimeout(3.0) | ||
| except OSError as error: | ||
| _LOGGER.error('failed to bind socket %s:%s, %s', UDP_IP, UDP_PORT, error) | ||
| sock.close() | ||
| return | ||
|
|
||
| try: | ||
| if broadcast: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be removed form the try, except block ... maybe in another
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what part are you referring to here? |
||
| sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | ||
| host = '255.255.255.255' | ||
|
|
||
| _LOGGER.debug('send_recv_msg %s [%s]', host, msg) | ||
| sock.sendto(msg.encode('utf-8'), (host, DDP_PORT)) | ||
|
|
||
| if receive: | ||
| return sock.recvfrom(1024) | ||
|
|
||
| sock.close() | ||
| except OSError as error: | ||
| _LOGGER.error('failed to send data using socket, %s', error) | ||
| sock.close() | ||
| return | ||
|
|
||
|
|
||
| def _send_msg(host, broadcast, msg): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it is a good idea to return siliently. The errors would not be catched anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuing just seems to break more, and the error is already reported, so I don't know what a better alternative would be.
basicly what you are trying is not working and you are informed why, in my opinion that seems better than breaking with an unhandled exception