Conflicts: src/wuerfelthreads/Start.java src/wuerfelthreads/view/WuerfelView.form src/wuerfelthreads/view/WuerfelView.javamaster
@@ -1,77 +0,0 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package netz; | |||
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.net.Socket; | |||
import java.util.logging.Logger; | |||
import ohmlogger.OhmLogger; | |||
/** | |||
* Builder Class | |||
* @author le | |||
*/ | |||
public class Client | |||
{ | |||
private static Logger lg = OhmLogger.getLogger(); | |||
private static final int PORT = 35000; | |||
private static final String IP_ADRESSE = "127.0.0.1"; | |||
public Client() throws IOException | |||
{ | |||
lg.info("Client: verbinde ..."); | |||
Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert! | |||
lg.info("Client: Verbindung hergestellt"); | |||
InputStream iStream = s.getInputStream(); | |||
OutputStream oStream = s.getOutputStream(); | |||
InputStreamReader isr = new InputStreamReader(iStream, "UTF-8"); | |||
OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8"); | |||
BufferedReader in = new BufferedReader(isr); | |||
//BufferedWriter out = new BufferedWriter(osr); | |||
PrintWriter out = new PrintWriter(osr); | |||
lg.info("Client: Stream initialisiert"); | |||
out.println("Hallo Du Server Du - ich bin der client"); | |||
out.flush(); // wirklich absenden!! | |||
lg.info("Client: Nachricht versendet"); | |||
String quittung = in.readLine(); // Achtung blockiert | |||
lg.info("Client: Quittung empfangen"); | |||
System.out.println("Client: Quittung EMPFANGEN - " + quittung); | |||
out.close(); | |||
in.close(); | |||
} | |||
/** | |||
* @param args the command line arguments | |||
*/ | |||
public static void main(String[] args) | |||
{ | |||
try | |||
{ | |||
new Client(); | |||
} | |||
catch (IOException ex) | |||
{ | |||
lg.severe(ex.toString()); | |||
} | |||
} | |||
} |
@@ -1,77 +0,0 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package netz; | |||
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.net.ServerSocket; | |||
import java.net.Socket; | |||
import java.util.logging.Logger; | |||
import ohmlogger.OhmLogger; | |||
/** | |||
* Builder Class | |||
* @author le | |||
*/ | |||
public class Server | |||
{ | |||
private static Logger lg = OhmLogger.getLogger(); | |||
private static final int PORT = 35000; | |||
public Server() throws IOException | |||
{ | |||
ServerSocket sSocket = new ServerSocket(PORT); | |||
lg.info("Server: Warte auf Verbindung ..."); | |||
Socket s = sSocket.accept(); // Achtung: blockiert! | |||
lg.info("Server: Verbindung akzeptiert"); | |||
InputStream iStream = s.getInputStream(); | |||
OutputStream oStream = s.getOutputStream(); | |||
InputStreamReader isr = new InputStreamReader(iStream, "UTF-8"); | |||
OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8"); | |||
BufferedReader in = new BufferedReader(isr); | |||
//BufferedWriter out = new BufferedWriter(osr); | |||
PrintWriter out = new PrintWriter(osr); | |||
lg.info("Server: Stream initialisiert"); | |||
lg.info("Server: warte auf Nachricht ..."); | |||
String nachricht = in.readLine(); // Achtung blockiert | |||
lg.info("Server: Nachricht empfangen"); | |||
System.out.println("Server: NACHRICHT EMPFANGEN - " + nachricht); | |||
out.println("Server -> ich habe die Nachricht erhalten"); | |||
lg.info("Server: Quittung versendet"); | |||
out.flush(); // wirklich absenden!! | |||
out.close(); | |||
in.close(); | |||
} | |||
/** | |||
* @param args the command line arguments | |||
*/ | |||
public static void main(String[] args) | |||
{ | |||
try | |||
{ | |||
new Server(); | |||
} | |||
catch (IOException ex) | |||
{ | |||
lg.severe(ex.toString()); | |||
} | |||
} | |||
} |
@@ -43,6 +43,30 @@ public class BtnController implements ActionListener | |||
@Override | |||
public void actionPerformed(ActionEvent e) | |||
{ | |||
if(e.getSource() == view.getBtnSetClient()) | |||
{ | |||
view.getLblType().setText("Client"); | |||
try | |||
{ | |||
model.startClient(36000, "127.0.0.1",new ChatController(view, model)); | |||
} | |||
catch (Exception ex) | |||
{ | |||
System.err.println(ex); | |||
ex.printStackTrace(); | |||
} | |||
} else { | |||
view.getLblType().setText("Server"); | |||
try | |||
{ | |||
model.startServer(36000, new ChatController(view, model)); | |||
} | |||
catch (Exception ex) | |||
{ | |||
System.err.println(ex); | |||
ex.printStackTrace(); | |||
} | |||
} | |||
} | |||
@@ -43,7 +43,10 @@ public class ChatController implements ActionListener | |||
public void actionPerformed(ActionEvent e) | |||
{ | |||
} | |||
public void upddateStatus(String status) | |||
{ | |||
view.getLblStatusDialog().setText(status); | |||
} | |||
} |
@@ -6,14 +6,134 @@ | |||
package netz.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.net.ServerSocket; | |||
import java.net.Socket; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.concurrent.Flow; | |||
import java.util.concurrent.SubmissionPublisher; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import netz.controller.ChatController; | |||
import ohmlogger.OhmLogger; | |||
/** | |||
* | |||
* @author chris | |||
*/ | |||
public class ChatModel | |||
public class ChatModel | |||
{ | |||
private static Logger lg = OhmLogger.getLogger(); | |||
private ServerRunnable serverRunnable; | |||
private ClientRunnable clientRunnable; | |||
// private ChatController controller; | |||
public ChatModel() | |||
{ | |||
} | |||
public void startServer(int PORT, ChatController chatcontroller) throws IOException | |||
{ | |||
ServerSocket sSocket = new ServerSocket(PORT); | |||
serverRunnable = new ServerRunnable(sSocket); | |||
chatcontroller.upddateStatus("Server: Warte auf Verbindung ..."); | |||
} | |||
public void startClient(int PORT, String ip_adresse, ChatController chatcontroller) throws IOException | |||
{ | |||
clientRunnable = new ClientRunnable(ip_adresse, PORT); | |||
chatcontroller.upddateStatus("Client: Warte auf Verbindung ..."); | |||
} | |||
} | |||
//public class Bandit implements Runnable | |||
//{ | |||
// private static Logger lg = OhmLogger.getLogger(); | |||
// | |||
// private BanditInfo info; | |||
// private volatile boolean laufend; | |||
// private ExecutorService eService; | |||
// private SubmissionPublisher<BanditInfo> iPublisher; | |||
// | |||
// public Bandit(int nr) | |||
// { | |||
// info = new BanditInfo(nr); | |||
// synchronized(this) | |||
// { | |||
// laufend = true; | |||
// } | |||
// eService = Executors.newSingleThreadExecutor(); | |||
// iPublisher = new SubmissionPublisher<>(); | |||
// | |||
// } | |||
// | |||
// /** | |||
// * startet würfeln | |||
// */ | |||
// public synchronized void start() | |||
// { | |||
// laufend = true; | |||
// eService.submit(this); | |||
// this.notifyAll(); | |||
// lg.info("Thread startet"); | |||
// } | |||
// | |||
// /** | |||
// * stopt würfeln | |||
// * | |||
// */ | |||
// public void stop() | |||
// { | |||
// synchronized(this) | |||
// { | |||
// laufend = false; | |||
// } | |||
// lg.info("Thread stopt"); | |||
// } | |||
// | |||
// public void addSubscription(Flow.Subscriber<BanditInfo> subscriber) | |||
// { | |||
// iPublisher.subscribe(subscriber); | |||
// } | |||
// | |||
// private synchronized void doWait() | |||
// { | |||
// try | |||
// { | |||
// this.wait(); | |||
// } catch (InterruptedException ex) | |||
// { | |||
// Logger.getLogger(Bandit.class.getName()).log(Level.SEVERE, null, ex); | |||
// } | |||
// } | |||
// | |||
// @Override | |||
// public void run() | |||
// { | |||
// | |||
// while(true) | |||
// { | |||
// | |||
// while(!laufend) | |||
// this.doWait(); | |||
// | |||
// try | |||
// { | |||
// Thread.sleep(10); | |||
// } catch (InterruptedException ex) | |||
// { | |||
// Logger.getLogger(Bandit.class.getName()).log(Level.SEVERE, null, ex); | |||
// } | |||
// info.setZaehlerWert((int)(Math.round(Math.random()*100) % 9) + 1); | |||
// iPublisher.submit(info); | |||
// } | |||
// } | |||
//} |
@@ -0,0 +1,95 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package netz.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.net.ServerSocket; | |||
import java.net.Socket; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import ohmlogger.OhmLogger; | |||
/** | |||
* | |||
* @author chris | |||
*/ | |||
public class ClientRunnable implements Runnable | |||
{ | |||
private static Logger lg = OhmLogger.getLogger(); | |||
private String ip_adresse; | |||
private int port; | |||
private ExecutorService eService; | |||
public ClientRunnable(String IP_ADRESSE, int PORT) throws IOException | |||
{ | |||
this.ip_adresse = IP_ADRESSE; | |||
this.port = PORT; | |||
eService = Executors.newSingleThreadExecutor(); | |||
this.start(); | |||
} | |||
public synchronized void start() | |||
{ | |||
eService.submit(this); | |||
this.notifyAll(); | |||
lg.info("Thread startet"); | |||
} | |||
@Override | |||
public void run() | |||
{ | |||
try | |||
{ | |||
lg.info("Client: verbinde ..."); | |||
Socket s = new Socket(ip_adresse, port); // Achtung: blockiert! | |||
lg.info("Client: Verbindung hergestellt"); | |||
InputStream iStream = s.getInputStream(); | |||
OutputStream oStream = s.getOutputStream(); | |||
InputStreamReader isr = new InputStreamReader(iStream, "UTF-8"); | |||
OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8"); | |||
BufferedReader in = new BufferedReader(isr); | |||
//BufferedWriter out = new BufferedWriter(osr); | |||
PrintWriter out = new PrintWriter(osr); | |||
lg.info("Client: Stream initialisiert"); | |||
out.println("Hallo Du Server Du - ich bin der client"); | |||
out.flush(); // wirklich absenden!! | |||
lg.info("Client: Nachricht versendet"); | |||
String quittung = in.readLine(); // Achtung blockiert | |||
lg.info("Client: Quittung empfangen"); | |||
System.out.println("Client: Quittung EMPFANGEN - " + quittung); | |||
out.close(); | |||
in.close(); | |||
} | |||
catch (Exception ex) | |||
{ | |||
Logger.getLogger(ServerRunnable.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
} |
@@ -0,0 +1,90 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package netz.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.net.ServerSocket; | |||
import java.net.Socket; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import ohmlogger.OhmLogger; | |||
/** | |||
* | |||
* @author chris | |||
*/ | |||
public class ServerRunnable implements Runnable | |||
{ | |||
private static Logger lg = OhmLogger.getLogger(); | |||
private ServerSocket sSocket; | |||
private Socket s; | |||
private ExecutorService eService; | |||
ServerRunnable(ServerSocket sSocket) throws IOException | |||
{ | |||
this.sSocket = sSocket; | |||
eService = Executors.newSingleThreadExecutor(); | |||
lg.info("Server: Warte auf Verbindung ..."); | |||
this.start(); | |||
} | |||
public synchronized void start() | |||
{ | |||
eService.submit(this); | |||
this.notifyAll(); | |||
lg.info("Thread startet"); | |||
} | |||
@Override | |||
public void run() | |||
{ | |||
try | |||
{ | |||
s = sSocket.accept(); // Achtung: blockiert! | |||
lg.info("Server: Verbindung akzeptiert"); | |||
InputStream iStream = s.getInputStream(); | |||
OutputStream oStream = s.getOutputStream(); | |||
InputStreamReader isr = new InputStreamReader(iStream, "UTF-8"); | |||
OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8"); | |||
BufferedReader in = new BufferedReader(isr); | |||
//BufferedWriter out = new BufferedWriter(osr); | |||
PrintWriter out = new PrintWriter(osr); | |||
lg.info("Server: Stream initialisiert"); | |||
lg.info("Server: warte auf Nachricht ..."); | |||
String nachricht = in.readLine(); // Achtung blockiert | |||
lg.info("Server: Nachricht empfangen"); | |||
System.out.println("Server: NACHRICHT EMPFANGEN - " + nachricht); | |||
out.println("Server -> ich habe die Nachricht erhalten"); | |||
lg.info("Server: Quittung versendet"); | |||
out.flush(); // wirklich absenden!! | |||
out.close(); | |||
in.close(); | |||
} | |||
catch (IOException ex) | |||
{ | |||
Logger.getLogger(ServerRunnable.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
} |
@@ -1,35 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | |||
<Properties> | |||
<Property name="defaultCloseOperation" type="int" value="3"/> | |||
</Properties> | |||
<SyntheticProperties> | |||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | |||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> | |||
</SyntheticProperties> | |||
<AuxValues> | |||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> | |||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> | |||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> | |||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> | |||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> | |||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> | |||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | |||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | |||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | |||
</AuxValues> | |||
<Layout> | |||
<DimensionLayout dim="0"> | |||
<Group type="103" groupAlignment="0" attributes="0"> | |||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/> | |||
</Group> | |||
</DimensionLayout> | |||
<DimensionLayout dim="1"> | |||
<Group type="103" groupAlignment="0" attributes="0"> | |||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/> | |||
</Group> | |||
</DimensionLayout> | |||
</Layout> | |||
</Form> |
@@ -1,100 +0,0 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package netz.view; | |||
/** | |||
* | |||
* @author hd | |||
*/ | |||
public class chatView extends javax.swing.JFrame | |||
{ | |||
/** | |||
* Creates new form chatView | |||
*/ | |||
public chatView() | |||
{ | |||
initComponents(); | |||
} | |||
/** | |||
* This method is called from within the constructor to initialize the form. | |||
* WARNING: Do NOT modify this code. The content of this method is always | |||
* regenerated by the Form Editor. | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents | |||
private void initComponents() | |||
{ | |||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | |||
getContentPane().setLayout(layout); | |||
layout.setHorizontalGroup( | |||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |||
.addGap(0, 400, Short.MAX_VALUE) | |||
); | |||
layout.setVerticalGroup( | |||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |||
.addGap(0, 300, Short.MAX_VALUE) | |||
); | |||
pack(); | |||
}// </editor-fold>//GEN-END:initComponents | |||
/** | |||
* @param args the command line arguments | |||
*/ | |||
public static void main(String args[]) | |||
{ | |||
/* Set the Nimbus look and feel */ | |||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |||
*/ | |||
try | |||
{ | |||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) | |||
{ | |||
if ("Nimbus".equals(info.getName())) | |||
{ | |||
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |||
break; | |||
} | |||
} | |||
} | |||
catch (ClassNotFoundException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(chatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (InstantiationException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(chatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (IllegalAccessException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(chatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (javax.swing.UnsupportedLookAndFeelException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(chatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
//</editor-fold> | |||
/* Create and display the form */ | |||
java.awt.EventQueue.invokeLater(new Runnable() | |||
{ | |||
public void run() | |||
{ | |||
new chatView().setVisible(true); | |||
} | |||
}); | |||
} | |||
// Variables declaration - do not modify//GEN-BEGIN:variables | |||
// End of variables declaration//GEN-END:variables | |||
} |