>> import socket
>> addr=('localhost', 10101)
>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> The Python code looks like it should work.
Indeed, it should work.
And regardless of whether it should work or not, no socket calls
should generate an NPE.
So this is definitely a bug.
> I am not sure if this is the jython code or not:
> def _do_send_nio(self, byte_array, socket_address, flags):
> byte_buf = java.nio.ByteBuffer.wrap(byte_array)
> bytes_sent = self.jchannel.send(byte_buf, socket_address)
> return bytes_sent
> def send(self, byte_array, flags):
> if self.mode == MODE_TIMEOUT:
> return self._do_send_net(byte_array, None, flags)
> return self._do_send_nio(byte_array, None, flags)
> If it is, it looks like maybe jython is passing a null
> pointer to DatagramChannel.send() as the target.
You're correct, that is the right piece of code. The error was that
when an UDP socket is connected, it doesn't need to pass an address,
so using the DatagramChannel.send() method is incorrect in this case,
since it expects a non-null address.
Instead, when connected, the DatagramChannel.write(ByteBuffer) method
should be used.
> Maybe for now it is best to stick with sendto()?
No need for that: I've checked in a fix at revision 6557. The revised
method looks like this
def _do_send_nio(self, byte_array, socket_address, flags):
byte_buf = java.nio.ByteBuffer.wrap(byte_array)
if self.jchannel.isConnected() and socket_address is None:
bytes_sent = self.jchannel.write(byte_buf)
bytes_sent = self.jchannel.send(byte_buf, socket_address)
Thanks to both Rene and Larry for reporting and commenting on this.
You may wish to download the latest from SVN.