client.java

来自「exemple for using java chat client + ser」· Java 代码 · 共 56 行

JAVA
56
字号
/*
 * client.java
 *
 * Created on 11 novembre 2008, 19:54
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package clientDT;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 *
 * @author Administrateur
 */
public class client {
    
    /** Creates a new instance of client */
    public client() {
    }
    public static void main(String agrs[]) throws UnknownHostException
    {
        InetAddress address = InetAddress.getLocalHost();
       String hote=address.getHostName();
        try
        {
          Socket S = new Socket(hote,13)  ;
          InputStream is = S.getInputStream();
          StringBuffer sb=new StringBuffer();
          //OutputStream os= new OutputStream();
          int c ;
          while((c=is.read())!=-1) sb.append((char)c);
          String dh=sb.toString().trim();
          System.out.println("la date et l'heure de la machine distant " +hote+" est :"+dh);
              
            
        }
        catch(UnknownHostException e)
        {
            System.out.println(e.getMessage());
        }
          catch(IOException e)
        {
            System.out.println(e.getMessage());
        }
        
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?