第五行有越界问题,不知如何解决
import *;import *;
public class lianxi51 {
public static void main(String[ ] args)throws UnknownHostException,IOException{
String name=args[0];
Socket s=new Socket(InetAddress.getLocalHost(),6666);
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
DataInputStream dis=new DataInputStream(s.getInputStream());
new Thread(new ReceiveMessage(dis)).start();
new Thread(new SendMessage(dos,name)).start();
}
}
class ReceiveMessage extends Thread{
private DataInputStream dis;
public ReceiveMessage(DataInputStream dis){
this.dis=dis;
}
public void run(){
try{
System.out.println(dis.readUTF());
}catch(IOException e){
e.printStackTrace();
}
}
}
class SendMessage extends Thread{
private DataOutputStream dos;
private String name;
public SendMessage(DataOutputStream dos,String name){
this.dos=dos;
this.name=name;
}
public void run(){
String info;
InputStreamReader is=new InputStreamReader(System.in);
BufferedReader bf=new BufferedReader(is);
while(true){
try{
info=bf.readLine();
dos.writeUTF(name+":"+info);
}catch (IOException e){
e.printStackTrace();
}
}
}
}