/**
*
* 服务端 1, 创建
*
*/
public class SeverSocketDemo {
public static void main(String args[]) throws IOException{
//创建服务端
ServerSocket ss = new ServerSocket(12345);
//等待客户端链接
Socket s = ss.accept();
//创建输出流,写到某个文件
PrintWriter pw= new PrintWriter( new FileWriter("c:/"+s.getInetAddress()+".txt"));
//创建输入流 并获取客户端输入流
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line ;
while((line=br.readLine())!=null){
System.out.println(line);
pw.println(line);
pw.flush();
}
br.close();
pw.close();