All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jpower.socket.ClientFactory Maven / Gradle / Ivy

There is a newer version: 0.0.5
Show newest version
package jpower.socket;

import jpower.core.Factory;
import jpower.core.utils.ExceptionUtils;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class ClientFactory implements Factory
{

    private final InetSocketAddress address;

    public ClientFactory(String host, int port)
    {
        address = new InetSocketAddress(host, port);
    }

    @Override
    public Client create()
    {
        Socket socket = new Socket();
        try
        {
            socket.connect(address);
            return new Client(socket);
        }
        catch (IOException e)
        {
            ExceptionUtils.throwUnchecked(e);
            return null;
        }
    }

    public static Client create(String host, int port)
    {
        return new ClientFactory(host, port).create();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy