Neue Class "Client1" mit Message Object
This commit is contained in:
parent
318abd4930
commit
6f61fbeebe
3 changed files with 73 additions and 21 deletions
68
src/client/Client1.java
Normal file
68
src/client/Client1.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
package client;
|
||||
|
||||
/**
|
||||
* @author berdan
|
||||
*/
|
||||
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
|
||||
|
||||
|
||||
public class Client1 {
|
||||
public Client1() throws IOException, ClassNotFoundException {
|
||||
Socket socket = new Socket( "localhost", 1236 );
|
||||
ObjectOutputStream oboust = new ObjectOutputStream(socket.getOutputStream());
|
||||
ObjectInputStream obinstr = new ObjectInputStream(socket.getInputStream());
|
||||
|
||||
Message senden = new Message( "berdan", "test" );
|
||||
System.out.println(senden);
|
||||
|
||||
// Message senden
|
||||
oboust.writeObject(senden);
|
||||
oboust.flush();
|
||||
|
||||
// Message erhalten
|
||||
Object erhalten = obinstr.readObject();
|
||||
System.out.println(erhalten);
|
||||
|
||||
oboust.close();
|
||||
obinstr.close();
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws IOException, ClassNotFoundException {
|
||||
new Client1();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Message implements Serializable {
|
||||
String username;
|
||||
String message;
|
||||
//String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
|
||||
LocalDateTime current = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
|
||||
String date = current.format(formatter);
|
||||
|
||||
|
||||
public Message( String username, String message ){
|
||||
this.username = username;
|
||||
this.message = message;
|
||||
//this.date = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "nickname=" + username +
|
||||
", message=" + message +
|
||||
", time=" + date;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,29 +1,10 @@
|
|||
/*
|
||||
* Copyright (C) 2021 eichehome
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package client;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* Hauptklasse des Clients
|
||||
* @version 0.0.1
|
||||
* @author eichehome
|
||||
*/
|
||||
|
||||
public class MainClient {
|
||||
|
||||
static Socket server = null;
|
||||
|
|
|
@ -24,6 +24,9 @@ import java.net.*;
|
|||
* @version 0.0.1
|
||||
* @author eichehome
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public class MainClient1 {
|
||||
|
||||
static Socket server = null;
|
||||
|
|
Loading…
Reference in a new issue