import java.net.*;
import java.io.*;
//客服端
class TextClient
{
public static void main(String[] args) throws Exception
{
Socket s = new Socket("192.168.1.2",10002);
BufferedReader br = new BufferedReader(new FileReader("e:\\1.txt"));
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
String line = null;
while((line = br.readLine()) != null)
{
out.println(line);
}
s.shutdownInput();
BufferedReader brs = new BufferedReader(new InputStreamReader(s.getInputStream()));
String str = brs.readLine();
System.out.println(str);
brs.close();
s.close();
}
}
// 服务端
class TextServer
{
public static void main(String [] args) throws Exception
{
ServerSocket ss = new ServerSocket(10002);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip+"........");
BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(new FileWriter("e:\\server.txt"),true);
String line = null;
while((line = bufIn.readLine()) != null)
{
out.println(line);
}
PrintWriter pw = new PrintWriter(s.getOutputStream(),true);
pw.println("上传成功!!");
out.close();
s.close();
ss.close();
}
}
能加载文件,但就是客户端没收到服务端反馈的消息呢?? |