|
|
@@ -4,16 +4,35 @@ |
|
|
|
*/ |
|
|
|
package ChatProgramm.model; |
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.net.ServerSocket; |
|
|
|
import java.net.Socket; |
|
|
|
import java.util.concurrent.Flow; |
|
|
|
import java.util.concurrent.Flow.Subscriber; |
|
|
|
import java.util.logging.Level; |
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @author ahren |
|
|
|
*/ |
|
|
|
public abstract class Transmitter implements Runnable{ |
|
|
|
static final int timeout = 10000; |
|
|
|
public abstract class Transmitter implements Runnable, Subscriber<String> { |
|
|
|
|
|
|
|
static final int timeout = 60000; |
|
|
|
private static final int PORT = 35000; |
|
|
|
|
|
|
|
private static Logger lg = Logger.getLogger("netz"); |
|
|
|
|
|
|
|
private Socket socket; |
|
|
|
private BufferedReader reader; |
|
|
|
private PrintWriter writer; |
|
|
|
|
|
|
|
public Transmitter() { |
|
|
|
|
|
|
@@ -21,9 +40,50 @@ public abstract class Transmitter implements Runnable{ |
|
|
|
|
|
|
|
public abstract void connect() throws IOException; |
|
|
|
|
|
|
|
public void initIO() { |
|
|
|
try { |
|
|
|
lg.info("Initialisiere reader und writer"); |
|
|
|
InputStream is = socket.getInputStream(); |
|
|
|
OutputStream os = socket.getOutputStream(); |
|
|
|
|
|
|
|
InputStreamReader isr = new InputStreamReader(is, "UTF-8"); |
|
|
|
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8"); |
|
|
|
|
|
|
|
reader = new BufferedReader(isr); |
|
|
|
writer = new PrintWriter(osr); |
|
|
|
lg.info("Server: Initialisierung abgeschlossen"); |
|
|
|
|
|
|
|
lg.info("Server: warte auf Nachricht"); |
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException ex) { |
|
|
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
} catch (IOException ex) { |
|
|
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onSubscribe(Flow.Subscription subscription) { |
|
|
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onNext(String item) { |
|
|
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(Throwable throwable) { |
|
|
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onComplete() { |
|
|
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody |
|
|
|
} |
|
|
|
|
|
|
|
} |