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