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();
    }
}

 

posted @ 2015-10-28 22:20  XYQ全哥  阅读(414)  评论(0编辑  收藏  举报