Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to get the information for WHOIS server. I have written a code in java. I am getting the connection reset error for some some domain. Follwoing method retrieves the WHOIS server information.

public void populateWhoisDetails(String domain) {
    logger.info("Retriving the Whois information for " + domain);
    Socket theSocket = null;
    BufferedReader in = null;
    PrintWriter writer = null;
    try {

        String whosisServer = whoisDNSModel.getWhosisServer();
        if (StringUtil.isNotEmpty(whosisServer)) {
            whoisDNSModel.setDomainName(domain);
            if (DomainProcessorEnum.VALID.equals(processorEnum)) {

                InetAddress inetAddress = InetAddress
                        .getByName(whosisServer);
                theSocket = new Socket();       
                theSocket.connect(new InetSocketAddress(inetAddress,43),120000);
                writer = new PrintWriter(theSocket.getOutputStream(), true);
                in = new BufferedReader(new InputStreamReader(
                        theSocket.getInputStream()));
                writer.println(domain+Constants.NEWLINE);
                writer.flush();
                String line = null;
                while ((line = in.readLine()) != null) {
                    if (line.contains(Constants.COLON)) {
                        String[] strArray = line.split(Pattern
                                .quote(Constants.COLON));
                        if (strArray[0].contains(Constants.REGISTRANT)) {
                            StringBuilder stringBuilder = populateRegistrantInformation(
                                    in, domain);
                            whoisDNSModel.setRegistrant(stringBuilder
                                    .toString());
                        } else if (null == whoisDNSModel
                                .getDnsCreatetionDate()
                                && strArray[0]
                                        .contains(Constants.CREATED_ON)
                                || strArray[0]
                                        .contains(Constants.CREATION_DATE)) {
                            String dateStr = strArray[1];
                            whoisDNSModel.setDnsCreatetionDate(dateStr);
                        }
                    }
                }

            }               
            theSocket.close();
        }

    } catch (UnknownHostException unknownHostException) {
        logger.log(Level.SEVERE,unknownHostException.getMessage(),unknownHostException);            
    }catch (IOException ioException) {
        logger.log(Level.SEVERE,ioException.getMessage(), ioException);
    }
    logger.info("Retrieved the Whois information for " + domain);
    }

Can any one please help me to resolve the issue?

share|improve this question
I think the server resets the connection for some reason. You may want to make sure the server is accepting your connection properly – Desolator Mar 29 at 6:10

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.