Author hulettbh
Recipients amak, hulettbh
Date 2012-03-12.15:14:17
SpamBayes Score 0.0
Marked as misclassified No
Message-id <>
In-reply-to <>
Glad to see that you're taking this seriously!

So the application I'm using this for is actually quite simple - my answers
to all of your questions are "No" - so I think that your "monkeypatch"
example will work well for me.  Thanks a lot for the solution!

We may have use for non-blocking sockets in the future though, so it would
be nice to see them implemented if you need to add it at some stage anyway.
 So to go back to your questions, it would be nice to have support for (1),
as well as (2), although that's less important.  (3) I suppose we could do
without - if there's no way to do it in cpython, personally I don't see any
reason to do it in jython.

On Sun, Mar 11, 2012 at 6:54 PM, Alan Kennedy <>wrote:

> Alan Kennedy <> added the comment:
> I didn't have any plans to implement multicast functionality, primarily
> because I wasn't aware that there was need for it. But you are using it, so
> let's have a think about it.
> Problem number one is that there is no support for multicast sockets under
> java.nio, i.e. although is a subclass of
>, there is no corresponding java.nio equivalent
> subclass. This is still true on java 6, which is the target for the next
> version of jython.
> Note that there is a multicast channel in java 7.
> But we currently have no plans to target java 7, so if support for
> multicast sockets were to be added to jython, it could only ever work on
> java 7 and later.
> As you may be aware, all sockets created with the jython socket module
> have a dual nature: they consist of a java.nio.channels.* object, which is
> used for all asynchronous operations and 'select'ing, and a*
> object, which is used for all other operations. There is no other choice
> than to work it this way, because neither of the or java.nio
> APIs contain all of the functionality required.
> You can see this if you look at the declaration of the
> "_datagram_socket_impl" class in the socket module. It creates both a
> "jchannel" and a "jsocket" attribute. In the case of multicast sockets,
> there is no way to create a "jchannel" object.
> Looking at the API for the java MulticastSocket class, I see other
> potential problems. Some of the methods take an "Interface" parameter, i.e.
> they allow you to specify a particular interface on which to send and
> receive multicasts. At the moment, there is no support in the jython socket
> module for modelling individual network interfaces: dealing with a specific
> interface requires specifying the IP address of the interface. (As far as I
> can tell, cpython doesn't permit modelling network interfaces either).
> (As an aside, this support for network interfaces will have to added at
> some stage, since support IPv6 scopes will require it)
> So, some questions.
> 1. Would you require non-blocking support for multicast sockets? This can
> not be implemented on jython until we hit java 7.
> 2. Would you require using select or poll on multicast sockets? Again,
> this would require java 7.
> 3. Does the cpython code that you are working with specify particular
> interfaces? How does it do that?
> If you could paste some sample code for your use case, that would be
> really helpful.
> Lastly, if your answer to all three questions is "no", then there should
> be a straightforward way to monkeypatch an UDP socket to be a multicast
> socket, by simply
> A: Creating a object, through the java APIs.
> B: Creating a jython UDP socket using socket.socket(socket.AF_INET,
> socket.SOCK_DGRAM, socket.IPPROTO_UDP)
> C: Assiging the "jsocket" attribute of the UDP socket to be the java
> Multicast socket.
> D: Only ever using the socket in blocking mode, and never using it in a
> select or poll call.
> Sample code
> # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> from import MulticastSocket, InetSocketAddress
> import socket
> ip, port = "", 6789
> jmultisock = MulticastSocket(InetSocketAdddress(ip, port))
> mysock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
> socket.IPPROTO_UDP)
> mysock.sock_impl.jsocket = jmultisock
> # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> _______________________________________
> Jython tracker <>
> <>
> _______________________________________
File name Uploaded
unnamed hulettbh, 2012-03-12.15:14:16
Date User Action Args
2012-03-12 15:14:17hulettbhsetrecipients: + hulettbh, amak
2012-03-12 15:14:17hulettbhlinkissue1846 messages
2012-03-12 15:14:17hulettbhcreate