public boolean connectServer(int port, String hostIp, String name) {
        // 连接服务器  
        try {  
            socket = new Socket(hostIp, port);// 根据端口号和服务器ip建立连接  
            writer = new PrintWriter(socket.getOutputStream());  
            reader = new BufferedReader(new InputStreamReader(socket  
                    .getInputStream()));  
            // 发送客户端用户基本信息(用户名和ip地址)  
            sendMessage(name + "@" + socket.getLocalAddress().toString());
            // 开启接收消息的线程  
            messageThread = new MessageThread(reader, textArea);  
            isConnected = true;// 已经连接上了  
            messageThread.start();  
            
            return true;  
        } catch (Exception e) {  
            textArea.append("port：" + port + "    IP：" + hostIp  
                    + "   的伺服器連線失敗QQ" + "\r\n");  
            isConnected = false;// 未连接上  
            return false;  
        }  
    }