Skip to content
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

Support UDP? #152

Open
LivInTheLookingGlass opened this issue May 21, 2017 · 2 comments
Open

Support UDP? #152

LivInTheLookingGlass opened this issue May 21, 2017 · 2 comments

Comments

@LivInTheLookingGlass
Copy link
Collaborator

It may take some effort, but it would be nice to support UDP. There will be some overhead, though, since we may need to avoid IP fragmentation. I'll tinker around a little in py2p and see if it works as-is, but I doubt it.

@LivInTheLookingGlass
Copy link
Collaborator Author

On the Python side of things it looks like it won't be too hard (fragmentation issues aside). It would just need a wrapper class of socket to deal with. Something like:

from socket import (socket, SOCK_DGRAM, error as SocketException)

class UDPSocket(object):
    def __init__(self):
        self.sock =  socket(type=SOCK_DGRAM)
        self.bind = sock.bind
        self.conn_addr = None

    def recv(self, size):
        if self.conn_addr is None:
            ret, self.conn_addr = self.sock.recvfrom(size)
            return ret
        else:
            return self.sock.recv(size)

    def send(self, data):
        if self.conn_addr is not None:
            self.sock.sendto(data, self.conn_addr)
        else:
            self.sock.send(data)  # potentially raises SocketException

This doesn't work in the current framework, since it has one node receiving all incoming data, but it would definitely work in the event based framework I'd like to switch to at some point. A similar thing can be done in Javascript, I imagine.

@LivInTheLookingGlass
Copy link
Collaborator Author

Javascript could probably support this pending p2p-today/js2p#4

It would require a mapping or two to make sure that the correct adapter gets called, but otherwise should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant