Beiträge von IcedApricot

    Liebe Leute,
    ich hab Montag Matura und muss fähig sein,
    diese Programme zu erklären.
    Ich wär euch sehr sehr dankbar.
    Ich will zwar auch auf die TU aber Chemie machen
    und Programmieren hat mir das Leben immer so schwer gemacht.


    Ich bitte, mir kurz zu erklären worums da geht.


    Danke!


    URL-Verbindung:
    Welche Klassen/Methoden werden verwendet?
    Wie erfolgt der Zugriff auf die Datenfelder?
    Erläutern Sie Parameter und Rückgabewerte

    public class URLConnectionReader
    {
    public static void main (String[] args) throws Exception{
    URL yahoo = new URL ("http://www.yahoo.com/");
    URLConnection yc = yahoo.openConnection();
    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    yc.getInputStream() ));
    String inputLine;

    while ((inputLine = in.readLine()) != null)

    System.out.println(inputLine);

    in.close();

    }

    ---------------------------------------------------------
    Sockets:
    Welche Klassen werden verwendet?
    Paramter?

    public class EchoClient {
    public static void main (String[] args){

    Socket echoSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;

    echoSocket = new Socket("taranis", 7);
    out = new PrintWriter(echoSocket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(
    echoSocket.getInputStream()));
    BufferedReader stdIn = new BufferedReader(
    new InputStreamReader(System.in));
    String userInput;

    while ((userInput = stdIn.readLine()) !=null) (
    out.println(userInput);
    System.out.println("echo: " + in.readLine());

    }

    out.close();
    in.close();
    stdIn.close();
    echoSocket.close();
    }

    }


    -----------------------------------------------------------------
    Datagramm:

    public class MainClass {
    private final static int BUFSIZE = 20;
    public static void main (String[] args) {
    int port = 80;

    DatagramSocket ds = new DatagramSocket(port);
    while (true) {

    byte buffer[] = new byte [BUFSIZE];
    Datagrampaket dp = new DatagramPacket (buffer, buffer.length);
    ds.receive(dp);
    String str = new String(dp.getData());
    System.out.println(str);
    }
    }
    }

    falls jemand Zeit hat, mir diese 3 schnell zu erklären.
    Muss das unbedingt können!

    URL-Verbindung:

    public class URLConnectionReader
    {
    public static void main (String[] args) throws Exception{
    URL yahoo = new URL ("http://www.yahoo.com/");
    URLConnection yc = yahoo.openConnection();
    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    yc.getInputStream() ));
    String inputLine;

    while ((inputLine = in.readLine()) != null)

    System.out.println(inputLine);

    in.close();

    }

    ---------------------------------------------------------
    Sockets:

    public class EchoClient {
    public static void main (String[] args){

    Socket echoSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;

    echoSocket = new Socket("taranis", 7);
    out = new PrintWriter(echoSocket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(
    echoSocket.getInputStream()));
    BufferedReader stdIn = new BufferedReader(
    new InputStreamReader(System.in));
    String userInput;

    while ((userInput = stdIn.readLine()) !=null) (
    out.println(userInput);
    System.out.println("echo: " + in.readLine());

    }

    out.close();
    in.close();
    stdIn.close();
    echoSocket.close();
    }

    }


    -----------------------------------------------------------------
    Datagramm:

    public class MainClass {
    private final static int BUFSIZE = 20;
    public static void main (String[] args) {
    int port = 80;

    DatagramSocket ds = new DatagramSocket(port);
    while (true) {

    byte buffer[] = new byte [BUFSIZE];
    Datagrampaket dp = new DatagramPacket (buffer, buffer.length);
    ds.receive(dp);
    String str = new String(dp.getData());
    System.out.println(str);
    }
    }
    }