chatclient.java

来自「java应用开发详解」· Java 代码 · 共 46 行

JAVA
46
字号
import java.net.*;import java.io.*;public class ChatClient {		Socket socket;	DataInputStream input;	DataInputStream user;	PrintStream output;		public ChatClient() {  		try {  			socket = new Socket("localhost",8123);  			input = new DataInputStream( socket.getInputStream() );			output = new PrintStream( socket.getOutputStream() );  		} catch(IOException e) {  			System.out.println("Abnormal chat client socket condition: "+ e );  		}		user = new DataInputStream( System.in );		String s = new String();				System.out.println("This is Chat Client.");		System.out.println("Enter your text: (Hit [Enter] twice to exit)");				do {			try {				s = user.readLine();				output.println(s);				output.flush();			} catch(IOException e) {}									System.out.println("User entered: " + s);		} while ( !s.equals("") );		output.close();	}	public static void main(String[] args) {		new ChatClient();	}}

⌨️ 快捷键说明

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