⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.java

📁 简单java聊天室
💻 JAVA
字号:
import java.io.*;import java.net.*;import javax.swing.JOptionPane;public class Client {    Socket socket=null;    public static String  host=null;    public static String  hostname=null;    private boolean connected = false;    public Client(){}    public boolean isConnected() { return connected; }        public Client(String getip,String hostname){    	host=getip;        this.hostname=hostname;        new ChatApplet(hostname);           }                       public Client(ChatApplet applet)   {    	    	        try {        	 System.out.println("获取IP");        	        	//login_frame login_information=new login_frame();        	        	           if(host.equals(""))JOptionPane.showMessageDialog(null,"请输入IP,该项不能为空!");        		        	else {        	     	        	//host=getip;        	//JOptionPane.showMessageDialog(null,host);            Thread.currentThread().sleep(2000);            System.out.println("准备连接......");                        try{            socket = new Socket(host,Server.port);            Thread.currentThread().sleep(1000);            System.out.println("发送请求");            connected = true;            System.out.println("正在连接服务......");            new ClientRecieveThread(socket, applet).start();            Thread.currentThread().sleep(1000);            System.out.println("连接成功.....");                                    }catch(ConnectException ex){            	            	System.out.print("连接失败\n");}          }        }        catch(java.lang.NullPointerException ex){        	JOptionPane.showMessageDialog(null,"请输入IP,该项不能为空!");        }        catch (Exception ex) {        	            applet.appendMessage(ex.getMessage());            ex.printStackTrace(System.err);        }                    }    public PrintWriter getOutputStream() throws IOException {        return new PrintWriter(socket.getOutputStream(), true);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -