1 package WebProgramingDemo; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.net.ServerSocket; 6 import java.net.Socket; 7 8 public class ServerSocketDemo { 9 10 /** 11 * @param args 12 * @throws IOException 13 */ 14 public static void main(String[] args) throws IOException { 15 16 ServerSocket ss = new ServerSocket(10002); 17 Socket s = ss.accept(); 18 String ip = s.getInetAddress().getHostAddress(); 19 System.out.println(ip + "....connected...."); 20 InputStream in = s.getInputStream(); 21 int len = 0; 22 byte[] buf = new byte[1024]; 23 len = in.read(buf); 24 System.out.println(new String(buf, 0, len)); 25 s.close(); 26 ss.close(); 27 } 28 29 }
时间: 2024-12-28 16:09:15