Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Add a sock argument to create_datagram_endpoint() #266

Closed
gvanrossum opened this issue Sep 24, 2015 · 8 comments
Closed

Add a sock argument to create_datagram_endpoint() #266

gvanrossum opened this issue Sep 24, 2015 · 8 comments

Comments

@gvanrossum
Copy link
Member

A number of requests for customization of datagram endpoints would be better served by having a sock argument to create_datagram_endpoint(), similar to create_server() and create_connection(). Example:

http://bugs.python.org/issue25230
http://bugs.python.org/issue23972

gvanrossum pushed a commit to gvanrossum/asyncio that referenced this issue Sep 25, 2015
@gvanrossum
Copy link
Member Author

See PR #267

@basak
Copy link

basak commented Sep 25, 2015

Is this intended to cover listening as a server as well as connecting as a client? I'm not clear on how to use this to get a socket listening.

@basak
Copy link

basak commented Sep 25, 2015

(and to test the PR I need both ends)

@gvanrossum
Copy link
Member Author

You don't connect or listen when using UDP (datagrams); those are TCP (streams) terms. You can send at any time using sendto() and whenever you receive something your protocol's datagram_received() is called. (There is a connect() for UDP sockets but it merely supplies a default address argument to sendto().)

@gvanrossum
Copy link
Member Author

Try looking at examples/udp_echo.py in the asyncio project.

@basak
Copy link

basak commented Sep 25, 2015

Ah, thanks. I was failing to combine my understanding of Unix domain socket streams with Internet datagrams. I didn't realise I had to bind the "client" end to something too.

I've refactored my code to bind each end to a local name manually (using the bind() method on a socket.socket object) and then using sock against create_datagram_endpoint() works with #267. My "trivial" use case of JSON-RPC over Unix datagram sockets is now working perfectly, thanks!

Though I have learnt the lesson that I need to bind each client to a path, it does still save serialization/deserialization that I'd have to do on a stream socket.

Many thanks for asyncio. It makes so many things trivial again.

@gvanrossum
Copy link
Member Author

You're welcome. (But are you sure you want to use datagrams for RPC?!?)

@gvanrossum
Copy link
Member Author

Addressed by commit 1e4ab9f by Chris Laws.

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

No branches or pull requests

2 participants