infodatagramme.java

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

JAVA
41
字号
/*
 * Infodatagramme.java
 *
 * Created on 12 novembre 2008, 11:40
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package UDP;
import java.net.*;
/**
 *
 * @author Administrateur
 */
public class Infodatagramme {
    
    /** Creates a new instance of Infodatagramme */
    public Infodatagramme() {
    }
    public static void main(String args[])
    {
        String s ="hello";
        byte[] donnees =s.getBytes();
        try
        {
            InetAddress id =InetAddress.getByName("www.google.com");
            int port = 7;
            DatagramPacket dp = new DatagramPacket(donnees,donnees.length,id,port);
            System.out.println("Ce paquet est adresse a"+dp.getAddress().getHostAddress()+"sur le port"
                    +dp.getPort());
            System.out.println("Il comporte "+dp.getLength()+"octects de donnees ");
            System.out.println(new String (dp.getData(),dp.getOffset(),dp.getLength()));
        }
        catch(UnknownHostException e)
        {
            System.err.println(e.getMessage());
        }
    }
}

⌨️ 快捷键说明

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