|
Re: Need help with Xsocket [message #871404 is a reply to message #871395] |
Sun, 13 May 2012 11:42 |
starnight pinazzo Messages: 3 Registered: May 2012 |
Junior Member |
|
|
I forgot to inform that's i want use it for connect to a OpenWebNet serveur ( domotic serveur)
my script is :
import java.io.IOException;
import java.net.SocketTimeoutException;
import org.xsocket.connection.INonBlockingConnection;
import org.xsocket.connection.MaxConnectionsExceededException;
import org.xsocket.connection.NonBlockingConnectionPool;
public class OpenWebNetClientPoolConnection
{
public static final int MAX_CONNECTION = 50;
public static final String DEFAULT_HOST = "192.168.1.120";
public static final int DEFAULT_PORT = 29900;
public static final long DEFAULT_TIMEOUT = 30 * 1000L;
private static OpenWebNetClientPoolConnection _instance;
private NonBlockingConnectionPool poolConnection;
private String host;
private int port;
private OpenWebNetClientPoolConnection(String host, int port)
{
poolConnection = new NonBlockingConnectionPool();
poolConnection.setMaxActive(MAX_CONNECTION);
this.host = host;
this.port = port;
}
public static OpenWebNetClientPoolConnection getInstance()
{
if (_instance == null)
{
_instance = new OpenWebNetClientPoolConnection(DEFAULT_HOST,DEFAULT_PORT);
}
return _instance;
}
public static OpenWebNetClientPoolConnection getInstance(String host, int port)
{
if (_instance == null)
{
_instance = new OpenWebNetClientPoolConnection(host,port);
}
return _instance;
}
public OpenWebNetClient newOpenWebNetClient() throws SocketTimeoutException, MaxConnectionsExceededException, IOException
{
INonBlockingConnection connection = poolConnection.getNonBlockingConnection(this.host, this.port);
return new OpenWebNetClient(connection);
}
public OpenWebNetClient newOpenWebNetClientMonitor() throws SocketTimeoutException, MaxConnectionsExceededException, IOException
{
INonBlockingConnection connection = poolConnection.getNonBlockingConnection(this.host, this.port);
return new OpenWebNetClient(connection, true);
}
public void destroyConnection(OpenWebNetClient client) throws IOException
{
NonBlockingConnectionPool.destroy(client.getConnection());
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09443 seconds