Merge pull request #4 from michieldwitte/master

removed forced logging, set receiver thread as daemon, Let the outbound payload be binary
This commit is contained in:
Giacomo Tanganelli 2018-03-05 17:06:39 +01:00 committed by GitHub
commit 6b74876f66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 21 deletions

View file

@ -14,18 +14,13 @@ from coapthon.messages.message import Message
from coapthon.messages.request import Request from coapthon.messages.request import Request
from coapthon.messages.response import Response from coapthon.messages.response import Response
from coapthon.serializer import Serializer from coapthon.serializer import Serializer
from coapthon.utils import create_logging
import collections import collections
__author__ = 'Giacomo Tanganelli' __author__ = 'Giacomo Tanganelli'
if not os.path.isfile("logging.conf"):
create_logging()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
class CoAP(object): class CoAP(object):
@ -174,6 +169,7 @@ class CoAP(object):
if self._receiver_thread is None or not self._receiver_thread.isAlive(): if self._receiver_thread is None or not self._receiver_thread.isAlive():
self._receiver_thread = threading.Thread(target=self.receive_datagram) self._receiver_thread = threading.Thread(target=self.receive_datagram)
self._receiver_thread.daemon = True
self._receiver_thread.start() self._receiver_thread.start()
def _start_retransmission(self, transaction, message): def _start_retransmission(self, transaction, message):

View file

@ -17,15 +17,12 @@ from coapthon.messages.message import Message
from coapthon.messages.request import Request from coapthon.messages.request import Request
from coapthon.resources.resource import Resource from coapthon.resources.resource import Resource
from coapthon.serializer import Serializer from coapthon.serializer import Serializer
from coapthon.utils import Tree, create_logging from coapthon.utils import Tree
__author__ = 'Giacomo Tanganelli' __author__ = 'Giacomo Tanganelli'
if not os.path.isfile("logging.conf"):
create_logging()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
class CoAP(object): class CoAP(object):

View file

@ -21,16 +21,12 @@ from coapthon.messages.request import Request
from coapthon.resources.remoteResource import RemoteResource from coapthon.resources.remoteResource import RemoteResource
from coapthon.resources.resource import Resource from coapthon.resources.resource import Resource
from coapthon.serializer import Serializer from coapthon.serializer import Serializer
from coapthon.utils import Tree, create_logging from coapthon.utils import Tree
__author__ = 'Giacomo Tanganelli' __author__ = 'Giacomo Tanganelli'
if not os.path.isfile("logging.conf"):
create_logging()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
class CoAP(object): class CoAP(object):

View file

@ -219,6 +219,10 @@ class Serializer(object):
fmt += "B" fmt += "B"
values.append(defines.PAYLOAD_MARKER) values.append(defines.PAYLOAD_MARKER)
if isinstance(payload, bytes):
fmt += str(len(payload)) + "s"
values.append(payload)
else:
fmt += str(len(bytes(payload, "utf-8"))) + "s" fmt += str(len(bytes(payload, "utf-8"))) + "s"
values.append(bytes(payload, "utf-8")) values.append(bytes(payload, "utf-8"))
# for b in str(payload): # for b in str(payload):

View file

@ -17,18 +17,13 @@ from coapthon.messages.response import Response
from coapthon.resources.resource import Resource from coapthon.resources.resource import Resource
from coapthon.serializer import Serializer from coapthon.serializer import Serializer
from coapthon.utils import Tree from coapthon.utils import Tree
from coapthon.utils import create_logging
import collections import collections
__author__ = 'Giacomo Tanganelli' __author__ = 'Giacomo Tanganelli'
if not os.path.isfile("logging.conf"):
create_logging()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
class CoAP(object): class CoAP(object):