Hallo zusammen, bin Anfänger in Thema Threads/Server und soll mir über einen Server eine Zeit schicken lassen über cmd-> telnet localhost 3737. Und damit ich das "Theaden" sehen kann, soll ich die Konsole 2 mal öffnen und die Zeit soll auf beiden Konsolen ablaufen. Aber ich bekomme Folgenden Fehler angezeigt mit dem ich nicht anzufangen weis:
java.net.BindException: Address already in use: bind
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:550)
at java.base/sun.nio.ch.Net.bind(Net.java:539)
at java.base/sun.nio.ch.NioSocketImpl.bind(NioSocketImpl.java:643)
at java.base/java.net.ServerSocket.bind(ServerSocket.java:396)
at java.base/java.net.ServerSocket.<init>(ServerSocket.java:282)
at java.base/java.net.ServerSocket.<init>(ServerSocket.java:173)
at tenet.telent.run(telent.java:21)
Kann mir jemand sagen was ich falsch mache ?
[CODE lang="java" title="telnet"]package tenet;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.iutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class telent extends Thread{
public void run() {
try (ServerSocket srvSock = new ServerSocket(3737)) {
while (true) {
Socket sock = srvSock.accept();
try (Reader in = new InputStreamReader
(sock.getInputStream(), "ASCII");
Writer out = new OutputStreamWriter
(sock.getOutputStream(), "ASCII")) {
while (true) {
out.write(Long.toString(System.currentTimeMillis() / 1000)
+ "\r\n");
out.flush();
if (in.ready()) {
break;
}try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
telent eins = new telent();
telent zwei = new telent();
eins.start();
zwei.start();
}
}[/CODE]
java.net.BindException: Address already in use: bind
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:550)
at java.base/sun.nio.ch.Net.bind(Net.java:539)
at java.base/sun.nio.ch.NioSocketImpl.bind(NioSocketImpl.java:643)
at java.base/java.net.ServerSocket.bind(ServerSocket.java:396)
at java.base/java.net.ServerSocket.<init>(ServerSocket.java:282)
at java.base/java.net.ServerSocket.<init>(ServerSocket.java:173)
at tenet.telent.run(telent.java:21)
Kann mir jemand sagen was ich falsch mache ?
[CODE lang="java" title="telnet"]package tenet;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.iutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class telent extends Thread{
public void run() {
try (ServerSocket srvSock = new ServerSocket(3737)) {
while (true) {
Socket sock = srvSock.accept();
try (Reader in = new InputStreamReader
(sock.getInputStream(), "ASCII");
Writer out = new OutputStreamWriter
(sock.getOutputStream(), "ASCII")) {
while (true) {
out.write(Long.toString(System.currentTimeMillis() / 1000)
+ "\r\n");
out.flush();
if (in.ready()) {
break;
}try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
telent eins = new telent();
telent zwei = new telent();
eins.start();
zwei.start();
}
}[/CODE]