本帖最后由 杜成龙 于 2013-10-24 09:06 编辑
今天一哥们让我传个文件给他,正好2周前看过网络编程,所以就想借机会试一下,我就写了个服务端的程序给他,然后我这边写了个客户端的程序,
结果,那哥们告诉我文件没传过去,我就在自己机子上试了下,还真是不行,但看到程序没有问题啊?所以想请高手帮看下,谢谢啦!
客户端程序:- import java.net.*;
- import java.io.*;
- class TextClient
- {
- public static void main(String[] args)throws Exception
- {
- BufferedReader bufr=new BufferedReader(new FileReader("UdpSend.java"));
- Socket s=new Socket("127.0.0.1",10008);
- PrintWriter out=new PrintWriter(s.getOutputStream(),true);
- BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
- String line=null;
- while ((line=bufr.readLine())!=null)
- {
- out.println(line);
- }
- String str=in.readLine();
- System.out.println(str);
- bufr.close();
- s.close();
- }
- }
复制代码 服务端程序:- import java.net.*;
- import java.io.*;
- class TextServer
- {
- public static void main(String[] args)throws Exception
- {
- ServerSocket ss=new ServerSocket(10008);
- Socket s=ss.accept();
- BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter out=new PrintWriter(s.getOutputStream(),true);
- PrintWriter pw=new PrintWriter("server.txt");
- String line=null;
- while ((line=in.readLine())!=null)
- {
- pw.println(line);
- pw.flush();
- }
- out.println("上传成功!");
- pw.close();
- s.close();
- ss.close();
- }
- }
复制代码 运行程序后,发现文件确实没传过来!程序写的好像没问题啊?
|