- /*
- 演示客户端和服务端
- 1、客户端:浏览器
- 服务端:自定义
- */
- import java.net.*;
- import java.io.*;
- class ServerDemo
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss=new ServerSocket(10086);
- Socket s=ss.accept();
- String ip=s.getInetAddress().getHostAddress();
- System.out.println(ip);
- PrintWriter out=new PrintWriter(s.getOutputStream(),true);
- out.println("<font color='pink' size='7'>你好<span style='color:red'>"+ip+"</span>,欢迎登录!</font>");
- s.close();
- ss.close();
- }
- }
复制代码 F:\自学练习>javac ServerDemo.java
F:\自学练习>java ServerDemo
Exception in thread "main" java.net.SocketException: Unrecognized Windows Socket
s error: 0: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at ServerDemo.main(ServerDemo.java:13) |
|