ReceiveAdapter adapter = new ReceiveAdapter(view,model); | ReceiveAdapter adapter = new ReceiveAdapter(view,model); | ||||
adapter.registerEvents(); | adapter.registerEvents(); | ||||
view.setSize(800,600); | |||||
view.setLocationRelativeTo(null); | |||||
view.setVisible(true); | view.setVisible(true); | ||||
} | } |
{ | { | ||||
ChatView view; | ChatView view; | ||||
Transmitter model; | Transmitter model; | ||||
int modus; | |||||
public ConnectController(ChatView view,Transmitter model,int modus) | public ConnectController(ChatView view,Transmitter model,int modus) | ||||
{ | { | ||||
this.view = view; | this.view = view; | ||||
this.model = model; | this.model = model; | ||||
this.modus = modus; | |||||
if(modus==0) | if(modus==0) | ||||
{ | { | ||||
Thread chatter = new Thread(model); | Thread chatter = new Thread(model); | ||||
@Override | @Override | ||||
public void actionPerformed(ActionEvent arg0) | public void actionPerformed(ActionEvent arg0) | ||||
{ | { | ||||
if(modus == 1) | |||||
{ | |||||
model.setIP_ADRESSE(view.getTxtzielIP().getText()); | model.setIP_ADRESSE(view.getTxtzielIP().getText()); | ||||
Thread chatter = new Thread(model); | Thread chatter = new Thread(model); | ||||
chatter.start(); | chatter.start(); | ||||
} | |||||
else | |||||
{ | |||||
view.getChatanzeige().setText("Server kann sich nicht verbinden"); | |||||
} | |||||
} | } | ||||
} | } |
{ | { | ||||
private static final Logger lg = OhmLogger.getLogger(); | private static final Logger lg = OhmLogger.getLogger(); | ||||
private static final int PORT = 35000; | private static final int PORT = 35000; | ||||
private String IP_ADRESSE = "127.0.0.1"; | |||||
private String IP_ADRESSE = ""; | |||||
int modus; | int modus; | ||||
private String nachricht; | private String nachricht; | ||||
{ | { | ||||
sSocket = new ServerSocket(PORT); | sSocket = new ServerSocket(PORT); | ||||
lg.info("Server: Warte auf Verbindung ..."); | lg.info("Server: Warte auf Verbindung ..."); | ||||
nachricht = "Server: Warte auf Verbindung ..."; | |||||
setChanged(); | |||||
notifyObservers(); | |||||
s = sSocket.accept(); // Achtung: blockiert! | s = sSocket.accept(); // Achtung: blockiert! | ||||
nachricht = "Verbunden mit Client"; | |||||
setChanged(); | |||||
notifyObservers(); | |||||
lg.info("Server: Verbindung akzeptiert"); | lg.info("Server: Verbindung akzeptiert"); | ||||
} | } | ||||
catch (IOException ex) | catch (IOException ex) | ||||
} | } | ||||
} | } | ||||
else if (modus == 1) | else if (modus == 1) | ||||
{ | |||||
{ | |||||
nachricht = "Verbinden mit "+ IP_ADRESSE; | |||||
setChanged(); | |||||
notifyObservers(); | |||||
lg.info("Client: verbinde ..."); | lg.info("Client: verbinde ..."); | ||||
try | try | ||||
{ | { |