Java:网络编程之登陆服务器
1.
客服端:浏览器(telnet)
服务端:自定义
2.
客服端:浏览器
服务端:TomCat服务器
3.
客服端:自定义
服务端:TomCat服务器
//例子如下:
import java.net.*; import java.io.*; class ServerDemo { public static void main(String[] args)throws Exception { ServerSocket ss = new ServerSocket(8080); Socket s = ss.accept(); System.out.println(s.getInetAddress().getHostAddress()); InputStream in = s.getInputStream(); byte[] buf = new byte[1024]; int len = in.read(buf); System.out.println(new String(buf,0,len)); PrintWriter out = new PrintWriter(s.getOutputStream(),true); out.println("<font color='read' 'size'=7>客户端你好</font>"); s.close(); ss.close(); } }
程序猿神奇的手,每时每刻,这双手都在改变着世界的交互方式!