Absoluter Pfusch der überhaupt gar nicht funktioniert!!!
This commit is contained in:
parent
1defd31146
commit
dc9d1d749a
@ -1,76 +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 chatprogramm;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Builder Class
|
||||
* @author le
|
||||
*/
|
||||
public class Client
|
||||
{
|
||||
private static final Logger lg = Logger.getLogger("netz");
|
||||
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,76 +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 chatprogramm;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Builder Class
|
||||
* @author le
|
||||
*/
|
||||
public class Server
|
||||
{
|
||||
private static final Logger lg = Logger.getLogger("netz");
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,12 @@
|
||||
|
||||
package chatprogramm;
|
||||
|
||||
import chatprogramm.controller.ConnectController;
|
||||
import chatprogramm.controller.ReceiveAdapterController;
|
||||
import chatprogramm.controller.SendController;
|
||||
import chatprogramm.model.Transmitter;
|
||||
import chatprogramm.view.ChatView;
|
||||
|
||||
/**
|
||||
* Builder Class
|
||||
* @author le
|
||||
@ -14,6 +20,12 @@ public class Start
|
||||
{
|
||||
public Start()
|
||||
{
|
||||
ChatView view = new ChatView();
|
||||
Transmitter model = new Transmitter();
|
||||
ConnectController conCon = new ConnectController(view, model);
|
||||
ReceiveAdapterController reiAdapCon = new ReceiveAdapterController(view, model);
|
||||
SendController sendCon = new SendController(view, model);
|
||||
view.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,13 @@
|
||||
|
||||
package chatprogramm.controller;
|
||||
|
||||
import chatprogramm.logger.OhmLogger;
|
||||
import chatprogramm.model.Transmitter;
|
||||
import chatprogramm.view.ChatView;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -17,10 +22,66 @@ public class ConnectController
|
||||
{
|
||||
private ChatView view;
|
||||
private Transmitter model;
|
||||
private static final Logger logger = OhmLogger.getLogger();
|
||||
private String ip = null;
|
||||
private int port = 0;
|
||||
|
||||
public ConnectController(ChatView view, Transmitter model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
chooseConnection();
|
||||
}
|
||||
|
||||
void chooseConnection()
|
||||
{
|
||||
Object[] options = {"Client", "Server"};
|
||||
int choice = JOptionPane.showOptionDialog(view, "Wähle deine Verbindungsart:", "Client oder Server", 0, 1, null, options, null);
|
||||
|
||||
if(choice == 1)
|
||||
{
|
||||
logger.info("Server");
|
||||
String port = JOptionPane.showInputDialog(view, "PORT eingeben");
|
||||
|
||||
logger.info("Port für Server ist: localhost:" + port);
|
||||
startServer();
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info("Client");
|
||||
port = Integer.parseInt(JOptionPane.showInputDialog(view, "PORT eingeben"));
|
||||
ip = JOptionPane.showInputDialog(view, "IP vom Server bitte");
|
||||
|
||||
logger.info("Client IP Adresse und Port ist: " + ip + ":" + port);
|
||||
startClient();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void startServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
model.createServer(port);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(ConnectController.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void startClient()
|
||||
{
|
||||
try
|
||||
{
|
||||
model.createClient(port, ip);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(ConnectController.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,14 @@ import java.util.logging.Logger;
|
||||
public class Client
|
||||
{
|
||||
private static final Logger lg = OhmLogger.getLogger();
|
||||
private static final int PORT = 35000;
|
||||
private static final String IP_ADRESSE = "127.0.0.1";
|
||||
private static int PORT = 35000;
|
||||
private static String IP_ADRESSE = "127.0.0.1";
|
||||
|
||||
public Client() throws IOException
|
||||
public Client(int port, String ip) throws IOException
|
||||
{
|
||||
if(port != 0) {this.PORT = port;};
|
||||
if(ip != null | ip != "") {this.IP_ADRESSE = ip;};
|
||||
|
||||
lg.info("Client: verbinde ...");
|
||||
Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert!
|
||||
lg.info("Client: Verbindung hergestellt");
|
||||
@ -60,18 +63,5 @@ public class Client
|
||||
in.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
new Client();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
lg.severe(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,10 +25,14 @@ import java.util.logging.Logger;
|
||||
public class Server
|
||||
{
|
||||
private static final Logger lg = OhmLogger.getLogger();
|
||||
private static final int PORT = 35000;
|
||||
private static int PORT = 35000;
|
||||
|
||||
public Server() throws IOException
|
||||
public Server(int port) throws IOException
|
||||
{
|
||||
if(port != 0)
|
||||
{
|
||||
this.PORT = port;
|
||||
}
|
||||
ServerSocket sSocket = new ServerSocket(PORT);
|
||||
lg.info("Server: Warte auf Verbindung ...");
|
||||
Socket s = sSocket.accept(); // Achtung: blockiert!
|
||||
@ -60,18 +64,4 @@ public class Server
|
||||
in.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
new Server();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
lg.severe(ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,29 @@
|
||||
|
||||
package chatprogramm.model;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Gerhard
|
||||
*/
|
||||
public class Transmitter
|
||||
{
|
||||
Server server;
|
||||
Client client;
|
||||
|
||||
public Transmitter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void createServer(int port) throws IOException
|
||||
{
|
||||
server = new Server(port);
|
||||
}
|
||||
|
||||
public void createClient(int port, String ip) throws IOException
|
||||
{
|
||||
client = new Client(port, ip);
|
||||
}
|
||||
}
|
||||
|
@ -2,21 +2,6 @@
|
||||
|
||||
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<NonVisualComponents>
|
||||
<Container class="javax.swing.JDialog" name="jDialogServerClient">
|
||||
|
||||
<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>
|
||||
</Container>
|
||||
<Menu class="javax.swing.JMenuBar" name="jMenuBar1">
|
||||
<SubComponents>
|
||||
<Menu class="javax.swing.JMenu" name="jMenu2">
|
||||
@ -38,7 +23,7 @@
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="true"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
@ -50,7 +35,7 @@
|
||||
<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"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-112,0,0,2,88"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
@ -74,6 +59,16 @@
|
||||
<Property name="text" type="java.lang.String" value="clear"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnServer">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jButton1"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jButton1"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JLayeredPane" name="chatContent">
|
||||
|
@ -27,14 +27,6 @@ public class ChatView extends javax.swing.JFrame
|
||||
return btnSend;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jDialogServerClient
|
||||
*/
|
||||
public javax.swing.JDialog getjDialogServerClient()
|
||||
{
|
||||
return jDialogServerClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the taEmpfangen
|
||||
*/
|
||||
@ -69,10 +61,11 @@ public class ChatView extends javax.swing.JFrame
|
||||
private void initComponents()
|
||||
{
|
||||
|
||||
jDialogServerClient = new javax.swing.JDialog();
|
||||
chatControll = new javax.swing.JLayeredPane();
|
||||
btnSend = new javax.swing.JButton();
|
||||
btnClear = new javax.swing.JButton();
|
||||
btnServer = new javax.swing.JButton();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
chatContent = new javax.swing.JLayeredPane();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
taEmpfangen = new javax.swing.JTextArea();
|
||||
@ -82,17 +75,6 @@ public class ChatView extends javax.swing.JFrame
|
||||
jMenu2 = new javax.swing.JMenu();
|
||||
jMenu3 = new javax.swing.JMenu();
|
||||
|
||||
javax.swing.GroupLayout jDialogServerClientLayout = new javax.swing.GroupLayout(jDialogServerClient.getContentPane());
|
||||
jDialogServerClient.getContentPane().setLayout(jDialogServerClientLayout);
|
||||
jDialogServerClientLayout.setHorizontalGroup(
|
||||
jDialogServerClientLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
);
|
||||
jDialogServerClientLayout.setVerticalGroup(
|
||||
jDialogServerClientLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
chatControll.setLayout(new java.awt.FlowLayout());
|
||||
@ -103,6 +85,12 @@ public class ChatView extends javax.swing.JFrame
|
||||
btnClear.setText("clear");
|
||||
chatControll.add(btnClear);
|
||||
|
||||
btnServer.setText("jButton1");
|
||||
chatControll.add(btnServer);
|
||||
|
||||
jButton1.setText("jButton1");
|
||||
chatControll.add(jButton1);
|
||||
|
||||
getContentPane().add(chatControll, java.awt.BorderLayout.PAGE_END);
|
||||
|
||||
chatContent.setLayout(new javax.swing.BoxLayout(chatContent, javax.swing.BoxLayout.PAGE_AXIS));
|
||||
@ -130,6 +118,7 @@ public class ChatView extends javax.swing.JFrame
|
||||
setJMenuBar(jMenuBar1);
|
||||
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
/**
|
||||
@ -184,9 +173,10 @@ public class ChatView extends javax.swing.JFrame
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnClear;
|
||||
private javax.swing.JButton btnSend;
|
||||
private javax.swing.JButton btnServer;
|
||||
private javax.swing.JLayeredPane chatContent;
|
||||
private javax.swing.JLayeredPane chatControll;
|
||||
private javax.swing.JDialog jDialogServerClient;
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JMenu jMenu2;
|
||||
private javax.swing.JMenu jMenu3;
|
||||
private javax.swing.JMenuBar jMenuBar1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user