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

📄 chatclient.java

📁 J2SE视频 第0讲_1 视频ppt及源码.rar
💻 JAVA
字号:
import java.io.*;
import java.net.*;

public class ChatClient
{
	Socket s = null;
	public ChatClient() throws Exception
	{
		s = new Socket("127.0.0.1", 8888);
	}
	
	public void send(String str) throws Exception
	{
		DataOutputStream dos = new DataOutputStream(s.getOutputStream());
		dos.writeUTF(str);
	}
	
	public void disconnect() throws Exception
	{
		s.close();
	}
	
	public static void main(String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader (
								new InputStreamReader(System.in));
		ChatClient cc = new ChatClient();
		String str = br.readLine();
		while(str != null && str.length() != 0)
		{
			cc.send(str);
			str = br.readLine();
		}
		cc.disconnect();
	}
}

⌨️ 快捷键说明

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