PDA

View Full Version : [JAVA] socket


AbuJaffa
11-06-2006, 14:26
C'è un modo per far si che la accept() sia non bloccante? :help:

sottovento
11-06-2006, 15:01
C'è un modo per far si che la accept() sia non bloccante? :help:

Hai gia' provato la getSoTimeout() ?
Altrimenti sei obbligato a creare un thread per risolvere il problema

High Flying
Sottovento

il_luridone
11-06-2006, 15:45
Spulciando in qua e in là ho visto ServerSocketChannel (http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/ServerSocketChannel.html) e SocketChannel (http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/SocketChannel.html) in java.nio.channels (http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/package-summary.html) .

Un ServerSocket ha un metodo getChannel() (http://java.sun.com/j2se/1.5.0/docs/api/java/net/ServerSocket.html#getChannel()) che dovrebbe appunto ritornare il ServerSocketChannel associato, su cui chiamare il metodo configureBlocking() (http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/spi/AbstractSelectableChannel.html#configureBlocking(boolean)) ereditato da AbstractSelectableChannel (http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/spi/AbstractSelectableChannel.html).

Tutto questo sulla carta, non l'ho mai fatto in pratica.

AbuJaffa
11-06-2006, 17:00
proverò... grazie.