| 发表于:2007-03-15 19:25:573楼 得分:0 |
但这个程序不能发送文件啊,我要既能收文件 又能发文件 就是还有个相当于下面这个类 class sendfile { fileinputstream fis;//读取文件变量 dataoutputstream dos;//网线路中写信息变量 datainputstream dis; string dir; string file; string targetip; sendfile(string f,string dir,string ip) { file =f; this.dir=dir; targetip =ip; } public void send() { byte bytebuffer[]= new byte[16000]; int temp; socket socket; try { fis=new fileinputstream(dir+file);//打开文件 }catch(ioexception e){} try { //建立连接 socket = new socket(targetip,4311); dos =new dataoutputstream(socket.getoutputstream()); dis = new datainputstream(socket.getinputstream()); //先向服务器端发一消息表示准备开始传文件 dos.writeutf( "ready? "+file); //当收到对方应答后就开始传送文件 if(dis.readutf().compareto( "ready ")==0) //开始读文件传送 { while ((temp= fis.read(bytebuffer)) != -1) { dos.write(bytebuffer); } fis.close(); dos.close(); } }catch(ioexception e1){} } } 但是如果在一个程序中的话,你看那个accept()服务器端运行到这时,就只有再那等,只能收文件 不能发啊,分开肯定可以 服务端程序和客户端 和起就不晓得怎么弄了 | | |
|