本帖最后由 程序爱好者 于 2014-5-12 11:17 编辑
- import java.io.*;
- import java.net.*;
- public class TextServer {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss=new ServerSocket(10011);
- Socket s=ss.accept();
- String ip=s.getInetAddress().getHostAddress();
- System.out.println(ip);
- BufferedReader bufr=new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter out=new PrintWriter(new FileWriter("Server.txt",true));
- String line=null;
- while((line=bufr.readLine())!=null)
- {
- out.println(line);
- }
- PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
- pw.println("上传成功!");
- s.close();
- ss.close();
- }
- }
- import java.net.*;
- import java.io.*;
- public class TextClient {
- public static void main(String[] args) throws Exception
- {
- Socket s=new Socket("192.168.1.100",10011);
- BufferedReader bufr=new BufferedReader(new FileReader("E:\\ACCP\\Myeclipse Workspaces\\网络编程\\src\\TCPfuzi\\TextClient.java"));
- PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
- String line=null;
- while((line=bufr.readLine())!=null)
- {
- pw.println(line);
- }
- s.shutdownOutput();
- BufferedReader buInt=new BufferedReader(new InputStreamReader(s.getInputStream()));
- String str=buInt.readLine();
- System.out.println("Server:"+str);
- bufr.close();
- s.close();
-
- }
- }
复制代码
看了毕老师网络编程这一块知识都是用两个dom命名窗口运行的,如果在MyEclipse上怎么运行,我先在MyEclipse上启动了TextServer 类,然后又切换到TextClient类上运行,结果为创建的文件是空的。
网络编程这一块在MyEclipse都不会运行,求热心同学教教我 |
|