From: Rene M. <rm...@ma...> - 2009-07-20 18:22:25
|
Hello I am working with jython 2.5 and Java 1.5. OS is debian/linux. Whenever I try to send a message (udp) with the socket send() method I get an exception. Using the socket sendto() method is ok. Is it not allowed to use socket send()? Example ----------------------------------------------------------------------- rene@querer:~$ java -jar Local/jython2.5.0/jython.jar Jython 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26) [Java HotSpot(TM) Server VM (Sun Microsystems Inc.)] on java1.5.0_19 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >>> addr = ('localhost', 10101) >>> s.connect(addr) >>> s.sendto("123", addr) 3 >>> s.send("123", addr) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/rene/Local/jython2.5.0/jython.jar/Lib/socket.py", line 992, in send File "/home/rene/Local/jython2.5.0/jython.jar/Lib/socket.py", line 451, in send File "/home/rene/Local/jython2.5.0/jython.jar/Lib/socket.py", line 437, in _do_send_nio at sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:218) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) java.lang.NullPointerException: java.lang.NullPointerException ----------------------------------------------------------------------- BTW, same result with Java 1.6 Kind regards René |
From: Larry R. <Larry@Riedel.org> - 2009-07-20 18:59:22
|
> >>> s.send("123", addr) "send" does not want to be provided an address... it is connected... just s.send("123")? Larry |
From: Rene M. <rm...@ma...> - 2009-07-20 21:01:04
|
Larry Riedel wrote: >> >>> s.send("123", addr) > > "send" does not want to be provided an address... > it is connected... just s.send("123")? > You are right. Sorry. Copy paste fault from my side to have a short and clear message for the mailimg list...... However s.send("123") gives the same fault: >>> import socket >>> addr=('localhost', 10101) >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >>> s.connect(addr) >>> s.send("123") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/rene/Local/jython2.5.0/jython.jar/Lib/socket.py", line 992, in send File "/home/rene/Local/jython2.5.0/jython.jar/Lib/socket.py", line 451, in send File "/home/rene/Local/jython2.5.0/jython.jar/Lib/socket.py", line 437, in _do_send_nio at sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:218) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) java.lang.NullPointerException: java.lang.NullPointerException >>> René |
From: Larry R. <Larry@Riedel.org> - 2009-07-20 22:04:29
|
> import socket > addr=('localhost', 10101) > > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > s.connect(addr) > s.send("123") The Python code looks like it should work. 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) else: 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. Maybe for now it is best to stick with sendto()? Larry |
From: Alan K. <jyt...@xh...> - 2009-07-21 23:14:09
|
[Rene] >> import socket >> addr=('localhost', 10101) >> >> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >> s.connect(addr) >> s.send("123") [Larry] > 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. [Larry] > 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) > else: > 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) else: bytes_sent = self.jchannel.send(byte_buf, socket_address) return bytes_sent Thanks to both Rene and Larry for reporting and commenting on this. You may wish to download the latest from SVN. https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython/Lib/socket.py Regards, Alan. |
From: Rene M. <rm...@ma...> - 2009-07-22 06:20:25
|
Alan Kennedy wrote: >> Maybe for now it is best to stick with sendto()? > No need for that: I've checked in a fix at revision 6557. > Thanks to both Rene and Larry for reporting and commenting on this. > You may wish to download the latest from SVN. > https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython/Lib/socket.py Thank you very much for the bug fix Alan! As I am working only with "jython.jar" in a Java environment: Is there a documentation elsewhere how to create "jython.jar" for the jython "trunk" version? Regards, René |
From: Alan K. <jyt...@xh...> - 2009-07-22 07:26:33
|
[Rene] > As I am working only with "jython.jar" in a Java environment: > Is there a documentation elsewhere how to create "jython.jar" for > the jython "trunk" version? Files in the Lib directory are not stored in jython.jar; they should still exist as plain files in the file system. Execute the following to find out the file path under which your socket module is stored. >>> import socket >>> print socket.__file__ HTH, Alan. |
From: David H. <Dav...@sa...> - 2009-07-22 13:43:35
|
> From: Alan Kennedy [mailto:jyt...@xh...] > ... > Files in the Lib directory are not stored in jython.jar; they should > still exist as plain files in the file system. Unless you use the Jython standalone jar, like I do. http://wiki.python.org/jython/InstallationInstructions#standalone-mode David H |
From: Alan K. <jyt...@xh...> - 2009-07-22 18:16:49
|
[Alan] >> Files in the Lib directory are not stored in jython.jar; they should >> still exist as plain files in the file system. [David] > Unless you use the Jython standalone jar, like I do. > > http://wiki.python.org/jython/InstallationInstructions#standalone-mode Thanks for taking the time to point out my mistake David. Aan. |
From: Alan K. <jyt...@xh...> - 2009-07-22 18:15:24
|
[Rene] > As I am working only with "jython.jar" in a Java environment: > Is there a documentation elsewhere how to create "jython.jar" for > the jython "trunk" version? You could update the socket.py in place in your existing jython.jar, like so At the same level as the jython.jar file, create a "Lib" directory. > mkdir Lib Copy the updated socket.py into that Lib directory. Then issue the following command, which will update the copy of Lib/socket.py in place inside the jar file. jar uvf jython.jar Lib/socket.py HTH, Alan. |
From: Rene M. <rm...@ma...> - 2009-07-23 05:22:59
|
Alan Kennedy wrote: >> As I am working only with "jython.jar" in a Java environment: >> Is there a documentation elsewhere how to create "jython.jar" for >> the jython "trunk" version? > > You could update the socket.py in place in your existing jython.jar Thank you very much. This is exactly what I have done today :) Regrads René |