import java.io.*;
import java.net.*;
class Client
{
public static void main(String[] args) throws Exception
{
Socket s = new Socket("ip",10008);
BufferedReader bufr = new BufferedReader(new FileReader("Xxx.java"));
PrintWriter pwOut = new PrintWriter(s.getOutputStream(),true);
BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
String str = null;
String line = null;
while((line=bufr.readLine())!=null)
{
pwOut.println(line);
}
s.shutdownOutput();
str = bufIn.readLine();
System.out.println("server:"+str);
bufr.close();
s.close();
}
}
class Server
{
public static void main(String[] args)throws Exception
{
ServerSocket ss = new ServerSocket(10008);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip+"....connected");
BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter pw = new PrintWriter(System.out,true);
String line = null;
while((line=bufIn.readLine())!=null)
{
pw.println(line);
}
PrintWriter pwOut = new PrintWriter(s.getOutputStream(),true);
String str = "上传成功";
pwOut.println(str);
pw.close();
s.close();
ss.close();
}
}
|