public final DccChat dccSendChatRequest(String nick, int timeout) {
        DccChat chat = null;
        try {
            ServerSocket ss = null;
            
            int[] ports = getDccPorts();
            if (ports == null) {
                // Use any free port.
                ss = new ServerSocket(0);
            }
            else {
                for (int i = 0; i < ports.length; i++) {
                    try {
                        ss = new ServerSocket(ports[i]);
                        // Found a port number we could use.
                        break;
                    }
                    catch (Exception e) {
                        // Do nothing; go round and try another port.
                    }
                }
                if (ss == null) {
                    // No ports could be used.
                    throw new IOException("All ports returned by getDccPorts() are in use.");
                }
            }
            
            ss.setSoTimeout(timeout);
            int port = ss.getLocalPort();
            
            InetAddress inetAddress = getDccInetAddress();
            if (inetAddress == null) {
                inetAddress = getInetAddress();
            }
            byte[] ip = inetAddress.getAddress();
            long ipNum = ipToLong(ip);
            
            sendCTCPCommand(nick, "DCC CHAT chat " + ipNum + " " + port);
            
            // The client may now connect to us to chat.
            Socket socket = ss.accept();
            
            // Close the server socket now that we've finished with it.
            ss.close();
            
            chat = new DccChat(this, nick, socket);
        }
        catch (Exception e) {
            // Do nothing.
        }
        return chat;
    }