Klassen in Model angelegt. Transmitter soll Händler zwischen Client Thread und Server Thread werden.
This commit is contained in:
parent
1764cd9f75
commit
1defd31146
77
src/chatprogramm/model/Client.java
Normal file
77
src/chatprogramm/model/Client.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.model;
|
||||||
|
|
||||||
|
import chatprogramm.logger.OhmLogger;
|
||||||
|
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 = 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
77
src/chatprogramm/model/Server.java
Normal file
77
src/chatprogramm/model/Server.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.model;
|
||||||
|
|
||||||
|
import chatprogramm.logger.OhmLogger;
|
||||||
|
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 = 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
src/chatprogramm/model/Transmitter.java
Normal file
19
src/chatprogramm/model/Transmitter.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Gerhard
|
||||||
|
*/
|
||||||
|
public class Transmitter
|
||||||
|
{
|
||||||
|
public Transmitter()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user