Example usage for org.apache.commons.net.nntp NNTPClient connect

List of usage examples for org.apache.commons.net.nntp NNTPClient connect

Introduction

In this page you can find the example usage for org.apache.commons.net.nntp NNTPClient connect.

Prototype

public void connect(InetAddress host) throws SocketException, IOException 

Source Link

Document

Opens a Socket connected to a remote host at the current default port and originating from the current host at a system assigned port.

Usage

From source file:org.ossmeter.platform.communicationchannel.nntp.local.NntpUtil.java

public static NNTPClient connectToNntpServer(NntpNewsGroup newsgroup) {

    NNTPClient client = new NNTPClient();
    client.setDefaultPort(newsgroup.getPort());
    String serverUrl = newsgroup.getUrl().substring(0, newsgroup.getUrl().lastIndexOf("/"));
    try {//from ww  w  .j  ava 2s . c  om
        client.connect(serverUrl);
        if (newsgroup.getAuthenticationRequired()) {
            client.authenticate(newsgroup.getUsername(), newsgroup.getPassword());
        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        System.err.println("SocketException while connecting to NNTP server: '" + newsgroup.getUrl() + "': "
                + e.getMessage());
        //           System.exit(1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.err.println(
                "IOException while connecting to NNTP server: '" + newsgroup.getUrl() + "': " + e.getMessage());
        //           System.exit(1);
    }
    return client;
}

From source file:org.ossmeter.platform.communicationchannel.nntp.NntpUtil.java

public static NNTPClient connectToNntpServer(NntpNewsGroup newsgroup) {

    NNTPClient client = new NNTPClient();
    client.setDefaultPort(newsgroup.getPort());
    String serverUrl = newsgroup.getUrl();

    if (serverUrl.endsWith("/")) {
        serverUrl = newsgroup.getUrl().substring(0, newsgroup.getUrl().lastIndexOf("/"));
    }/*from  www  .  j a v a2 s .  c  o  m*/

    try {
        client.connect(serverUrl);
        if (newsgroup.getAuthenticationRequired()) {
            client.authenticate(newsgroup.getUsername(), newsgroup.getPassword());
        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        System.err.println("SocketException while connecting to NNTP server: '" + newsgroup.getUrl() + "': "
                + e.getMessage());
        e.printStackTrace();
        //           System.exit(1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.err.println(
                "IOException while connecting to NNTP server: '" + newsgroup.getUrl() + "': " + e.getMessage());
        e.printStackTrace();
        //           System.exit(1);
    }
    return client;
}