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

📄 yylchatclient.java

📁 使用Java实现的基于TCP协议的通信的小的聊天程序的客户端
💻 JAVA
字号:

import java.io.*; 
import java.awt.*; 
import java.awt.event.*; 
import java.net.*; 

import javax.swing.JFrame;

public class YylChatClient extends Frame 
{ 
 

TextField tf=new TextField(20); 
TextArea ta=new TextArea(); 
Socket client; 
InputStream in; 
BufferedReader br; 
OutputStream out; 
BufferedWriter bw; 
public YylChatClient() 
{ 
super("客户端"); 
add("North",tf); 
add("Center",ta); 
setSize(400,400); 
show(); 
try 
{ 
client=new Socket("localhost",8189); 
ta.append("Connect to:"+client.getInetAddress().getHostName()+"\n\n"); 
in=client.getInputStream(); 
br=new BufferedReader(new InputStreamReader(in)); 
out=client.getOutputStream(); 
bw=new BufferedWriter(new OutputStreamWriter(out)); 
} 
catch(IOException ioe){} 
while(true) 
{ 
try 
{ 
byte[] buf=new byte[200]; 
in.read(buf); 
String str=new String(buf); 
ta.append("杨叶龙 说:"+str); 
ta.append("\n"); 
} 
catch(IOException e){} 
} 
} 
public boolean action(Event e,Object o) 
{ 
try 
{ 
String str=tf.getText(); 
byte[] buf=str.getBytes(); 
tf.setText(null); 
out.write(buf); 
ta.append("客户端 说:"+str); 
ta.append("\n"); 
} 
catch(IOException ioe){} 

return true; 

} 
public static void main(String args[]) 
{ 
	YylChatClient yyl=new YylChatClient(); 
    yyl.dispose();
    System.exit(0);

} 

} 

⌨️ 快捷键说明

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