Hello, i have been trying to use some async sockets , and after some tryes and
google reading i have found that there is no select module on jython. So, i
just jumped to the next solution, that is, using java native Selectors...
but for some reason my code doesn't works. It's almost the same example from
Java translated to jypthon.
It opens a socket, accepts a connection... but cant read from the channel!!
this is the code... some ideas?
from java.io import *
from java.net import *
from java.nio import *
from java.nio.channels import *
from java.nio.charset import *
selector = Selector.open()
# // Create two non-blocking server sockets on 80 and 81
ssChannel1 = ServerSocketChannel.open()
ssChannel1.configureBlocking(0)
ssChannel1.socket().bind(InetSocketAddress(8000))
ssChannel2 = ServerSocketChannel.open()
ssChannel2.configureBlocking(0)
ssChannel2.socket().bind(InetSocketAddress(8001))
# // Register both channels with selector
ssChannel1.register(selector, SelectionKey.OP_ACCEPT)
ssChannel2.register(selector, SelectionKey.OP_ACCEPT)
print "serving..."
while (1):
# // Wait for an event
selector.select();
# // Get list of selection keys with pending events
it = selector.selectedKeys().iterator()
# // Process each key
while (it.hasNext()):
# // Get the selection key
selKey = it.next()
# # // Remove it from the list to indicate that it is being processed
it.remove()
# // Check if it's a connection request
if (selKey.isAcceptable()):
# // Get channel with connection request
ssChannel = selKey.channel()
buf = ""
i = ssChannel.read(buf)
if i != -1:
print buf
# // See e178 Accepting a Connection on a ServerSocketChannel
# // for an example of accepting a connection request
thanks
Ivan Hernandez
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play:
http://sourceforge.net/geronimo.php_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users