第一个JAVA文件:
package com.crazy;
import java.net.*;
import java.awt.*;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;public class CrazyServer {

public static void main(String[] args) {
new RunServer().runServer();
new RunClient().runClient();
}




}
//发送...
class RunServer extends Frame implements ActionListener {
DatagramPacket dp = null;
DatagramSocket ds = null;
TextField tfText = new TextField(); TextArea ta = new TextArea();

byte[] buf = null;

public void runServer() {
//buf = new byte[1000];
/*buf = (new String("你也好")).getBytes();

try{

dp = new DatagramPacket(buf,buf.length,new InetSocketAddress("127.0.0.1",9090));

ds = new DatagramSocket(6060);
}catch(SocketException e1) {
e1.printStackTrace();
}catch(IOException e2) {
e2.printStackTrace();
}
try{
ds.send(dp);

}catch(IOException e) {
e.printStackTrace();
}


}*/

setLocation(400, 300);
this.setSize(300, 300);
add(tfText, BorderLayout.SOUTH);
add(ta, BorderLayout.NORTH);
pack();


this.addWindowListener(new WindowAdapter() { @Override
public void windowClosing(WindowEvent arg0) { System.exit(0);
} });
tfText.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
byte[] buf; buf = new String(tfText.getText()).getBytes(); try {

dp = new DatagramPacket(buf, buf.length/*,new InetSocketAddress("127.0.0.1",10000)*/);
dp.setSocketAddress(new InetSocketAddress("127.0.0.1", 10000)); 
ds = new DatagramSocket();
ds.send(dp);
String str = tfText.getText();
ta.setText(ta.getText() + str + '\n');
tfText.setText("");

} catch (IOException e1) {
e1.printStackTrace();


  }finally {
ds.close();
}
}}
//收取..
class RunClient {
DatagramPacket dp1 = null;
DatagramSocket ds1 = null;

byte[] buf1 = null;

public void runClient() {
buf1 = new byte[1000];
//buf = (new String("你也好")).getBytes();

try{

dp1 = new DatagramPacket(buf1,buf1.length);

ds1 = new DatagramSocket(9090);
}catch(SocketException e1) {
e1.printStackTrace();
}catch(IOException e2) {
e2.printStackTrace();
}

while(true) {
try {
ds1.receive(dp1);


System.out.println(new String(buf1,0,dp1.getLength()));



} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}

}
}
}第二个JAVA文件:package com.crazy;import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;public class CrazyClient extends Frame implements ActionListener {
byte[] buf; DatagramPacket dp = null; DatagramSocket ds = null; TextField tfText = new TextField(); TextArea ta = new TextArea();

public static void main(String[] args) {
CrazyClient cc = new CrazyClient();
cc.launchFrame();
//Thread th = new Thread();
//th.run();
//LunClient cl = new LunClient(cc);
// new LunServer(cc).lunServer();
new RunClient().runClient();


} public void launchFrame() { setLocation(400, 300);
this.setSize(300, 300);
add(tfText, BorderLayout.SOUTH);
add(ta, BorderLayout.NORTH);
pack();


this.addWindowListener(new WindowAdapter() { @Override
public void windowClosing(WindowEvent arg0) { System.exit(0);
} });
tfText.addActionListener(this);
setVisible(true);
}
//发送..
public void actionPerformed(ActionEvent e) {
byte[] buf; buf = new String(tfText.getText()).getBytes(); try {

dp = new DatagramPacket(buf, buf.length/*,new InetSocketAddress("127.0.0.1",10000)*/);
dp.setSocketAddress(new InetSocketAddress("127.0.0.1", 9090)); 
ds = new DatagramSocket();
ds.send(dp);
String str = tfText.getText();
ta.setText(ta.getText() + str + '\n');
tfText.setText("");

} catch (IOException e1) {
e1.printStackTrace();


  }finally {
ds.close();
}
}
}
/*class LunClient {
DatagramPacket dp = null; DatagramSocket ds = null; byte[] buf = null; CrazyClient c; LunClient(CrazyClient c) {
this.c = c;
buf = new byte[1000];
// buf = (new String("你太好了!")).getBytes();
// buf = (c.ta.getText()).getBytes(); try { dp = new DatagramPacket(buf, buf.length); ds = new DatagramSocket(9090);

} catch (SocketException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}

Thread th = new Thread(new RunReceive());
th.start();
}


class RunReceive implements Runnable {
public void run() {
while (true) {
try {
ds.receive(dp); System.out.println(new String(buf, 0, dp.getLength())); } catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} }
}
}
}*/
//收取..
class LunClient {
DatagramPacket dp = null;
DatagramSocket ds = null;

byte[] buf = null;

public void runClient() {
buf = new byte[1000];
//buf = (new String("你也好")).getBytes();

try{

dp = new DatagramPacket(buf,buf.length);

ds = new DatagramSocket(10000);
}catch(SocketException e1) {
e1.printStackTrace();
}catch(IOException e2) {
e2.printStackTrace();
}

while(true) {
try {
ds.receive(dp);


System.out.println(new String(buf,0,dp.getLength()));



} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}

}
}
}
请高手看看,我想实现两个文件互相访问,但是如果两个文件同时启动的话,会出现端口已经绑定的错误出现,请帮忙解决一下,谢谢..