Client端:
import java.io.*; 
import java.awt.*; 
import java.awt.event.*; 
import java.net.*; public class ChatC extends Frame 

TextField tf=new TextField(20); 
TextArea ta=new TextArea(); 
Socket client; 
InputStream in; 
BufferedReader br; 
OutputStream out; 
BufferedWriter bw; 
public ChatC() 

super("Client"); 
add("North",tf); 
add("Center",ta); 
setSize(250,250); 
show(); 
try 

client=new Socket("127.0.0.1",5555); 
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("Server:"+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("Client:"+str); 
ta.append("\n"); 

catch(IOException ioe){} 
return true; 
} public static void main(String args[]) 

new ChatC(); 


那位大大能帮我下这个忙?重谢啊我 都搞一下午了 都没整个什么出来。。头晕晕啊。

解决方案 »

  1.   

    55555我才学JAVA一个星期老师给我们这个课题让我们去做。。我实在是看不懂啊 他要写流程图。无语了。。还要解释出来  翻书看不懂啊
      

  2.   

    本来就是上课又不讲清楚。。听也听不懂。。听说老师都是自学JAVA的。。上次我那了个聊天室的程序给他看 让他帮我讲解下 他都把书拿去看了半个小时才给我说怎么回事。。结果程序还是没运行成功