<?php
$host="localhost";
$port=6000;
$timeout=5;
?>
<html>
<head>
<title>Demo</title>
</head>
<body>
<?php
// Falls Formular abgesendet....
if ($sent == 1){
$sk=fsockopen($host,$port,$errnum,$errstr,$timeout) ;
if (!is_resource($sk)) {
exit("connection fail: ".$errnum." ".$errstr) ;
}
// Eingegebenen Text senden....
fwrite($sk,$text);
$dati="" ;
// Antwort empfangen
while (!feof($sk)) {
$dati = fgets ($sk, 1024);
}
echo "".$dati;
}
?>
<form name="form1" method="get" action="<?php echo $PHP_SELF; ?>">
<input name="sent" type="hidden" value="1">
Text eingeben:
<input name="text" type="text" size="20">
<input type="submit" name="Submit" value="Abschicken">
</form>
</body>
</html>
import java.net.*;
import java.io.*;
public class Server {
public static void main(String[] argv){
ServerSocket anschluss= null;
try {
anschluss = new ServerSocket(6000);
}
catch (IOException e){
System.out.println(e);
}
while(true){
try {
Socket client = anschluss.accept();
InputStreamReader portLeser = new InputStreamReader(client.getInputStream());
BufferedReader eingabe = new BufferedReader(portLeser);
PrintWriter out = new PrintWriter(new OutputStreamWriter(client.getOutputStream()));
String text = eingabe.readLine();
// Input ausgeben
System.out.println(text);
// Echo Input (Input zurueckgeben)
out.println(text);
out.flush();
out.close();
}
catch (IOException e){
System.out.println(e);
}
}
}
}