注册 登录
编程论坛 JAVA论坛

第五行有越界问题,不知如何解决

七小袋 发布于 2015-12-11 15:35, 2679 次点击
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();
            }
        }
    }
}
4 回复
#2
七小袋2015-12-11 16:00
奈何没人能看出来
#3
林月儿2015-12-11 20:51
命令行参数没输入吧?
#4
limingcong012015-12-22 19:39
没看出来
#5
crazyman282015-12-30 16:54
Socket编程。。我没接触过。
1